Subj : Re: Performance Advice on Maintaining Many Contexts To : Peter Kyme From : Brendan Eich Date : Wed Mar 02 2005 05:22 pm Peter Kyme wrote: > My problem involves a system containing a large number (> 100) of > objects, each of which has an associated Spidermonkey context. > > The objects execute a small javascript repeatedly, iterating until > termination. This javascript is user defined, and so may contain > arbitrary local variables, Do you really mean local as in function-local, or just top-level vars private to the script? If the latter, you need a global object per script to hold those global vars, but not a context per script unless you are executing scripts concurrently. > which was my motivation for creating a > context per object (no multithreading is involved). A JSContext is the state you need to execute concurrently, so if you have only one thread, you need no more than one JSContext. Why did you make a context per object? > This appears to work well, but I've encountered a nasty performance > issue at cleanup time. Running the program through once, without doing > any memory cleanup takes ~1.2s. If I then add code to destroy the JS > contexts before exits, the program take ~17s to execute. What version of the engine are you using? /be .