Subj : Re: Lazy resolution and super globals To : Damian Slee From : Brendan Eich Date : Mon Sep 06 2004 09:47 pm Damian Slee wrote: > Hi all, > Trying to wrap my head around some concepts for speed and size. > > >>>use lazy standard class resolution instead of > > What is the advantage of this? > - Speed up initialisation. Or move it till/if it is needed. > - possible less memory usage Both, of course. Standard class constructors and global functions are defined only on demand, so if a script runs without needing any, then none are created. > does this mean only the minimum required standard classes are created when needed? None are created unless you call JS_InitStandardClasses, in which case all are. If you instead use JS_ResolveStandardClass from your global class's resolve hook, then the granularity is pretty fine. All global properties related to a given class may be created along with that class's constructor being defined (e.g., parseInt and parseFloat along with Number). > If I was to re-use a context to run a fresh script, so I don't lose > the CPU time to re-create the context, how do I reset the globalObject? > Delete and NewObject, or JS_ClearScope()? What do you mean by "Delete"? Just JS_SetGlobalObject will do, the GC should do the rest, unless you have roots to clear -- such root clearing is of course up to your code, since it added the roots. > I read somewhere on google groups that shared superglobal is not > recommended for multithreaded (thread/context) environments. > Is that still the case, even with JS_THREADSAFE & NSPR? I don't know where you read that, but it was probably an echo of something about how the shared superglobal can't be sealed (made immutable), so different threads could set and get properties on it, interfering with one another. Now we have JS_SealObject, so that echo needs to die off. But, there's still not much point in a super-global if you use lazy class resolution, as you cannot lazily add standard class constructors, etc., on demand to a sealed object. /be .