Subj : Re: JavaScript performance in the real world To : Pete Diemert From : Brendan Eich Date : Fri Sep 17 2004 06:35 pm Pete Diemert wrote: > ...fairly typical stuff. The problem is that opening a recordset object, as > you might expect, can be costly and code similar to that above will chew up > literally 10's of megabytes of heap space with recordset objects in a matter > of seconds. When a GC finally kicks in everything is cleaned up but we can > see the working set issue easily becoming a constraint in many real world > scenarios where we wish to use JavaScript. Then it's up to your embedding to run the GC more often. Pending a better GC in the engine that scans while allocating (an incremental GC), you have to call JS_GC or JS_MaybeGC. You should certainly use JS_SetBranchCallback to configure a branch callback on each JSContext that will increment an unsigned counter associated with the context (perhaps kept in its private data, got and set via JS_Get/SetContextPrivate), and for every (counter & 0x3fff) or so backward branches, call JS_MaybeGC. > One other interesting note is > that we have attempted to call GC at periodic moments throughout processing > on return from native function calls (e.g. every so many seconds) but we > find that the GC is CONSIDERABLY slower when the scriptdepth is greater than > 0 (we have scenarios of approximately 5K JS objects allocated where the GC > will take 30 seconds). If the scriptdepth is 0 the GC will be nearly > instaneous (perhaps extra roots are created for objects in frame?). Possibly, but if so, then you can always try JS_MaybeGC on return to outermost level. That won't hurt much at all if the heap hasn't grown. > Understanding that JavaScript is a GC / "managed" environment and that, > architecturally we could be trying to fit a square peg in a round hole, are > there some techniques that we could use to make this system work better? > Perhaps just solving the slow GC problem will get us there. Any suggestions > or insight would be greatly appreciated. I hope the above helps. If not, let me know. /be .