Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Statistics of using non-shared scopes

0 views
Skip to first unread message

Attila Szegedi

unread,
Nov 5, 2009, 7:38:36 AM11/5/09
to rhino Dev
People are often asking on the Rhino list about using shared top-level
scopes for standard objects in server setting for increased speed and
possible memory conservation. I'm now redesigning a system that
originally used shared scopes, and am experimenting with not using
them. The reason for it is that the possibility for crosstalk between
otherwise isolated script executions is there, and it also tempts one
to use dynamic scopes (which, again, I frown upon especially if I also
wish to leverage lexical scoping for OO encapsulation and don't need
any nasty surprises there).

So, I did a small experiment and concluded that:

I can create 3543 scopes with Context.initStandardObject() in a 64MB
heap before running out of memory. This translates to circa 18.5KB of
RAM per one.

They are created in about 5 seconds, yielding 1.4 msec for creation of
one. (Java 6, Mac OS X 10.6.1 on an Intel Core 2 Duo at 2.4GHz)

When serialized, one such scope takes up 11076 bytes. Also, if you're
serializing your scopes (i.e. as part of a continuations-based
framework), you'd incur some of this anyway even if you used shared
scopes for standard objects, as part of the serialization are,
obviously, Java class descriptors. For comparison, serializing two
initStandardObject() scopes takes up only 18917 bytes. This means the
scope data itself weighs at 7841 bytes, and 3235 is one-time overhead
of class descriptors you'd incur anyway. So, your serialization
increase is 7841 bytes per saved script state. (Again, roughly - this
assumes your serialized scopes would have one instance of every native
JS class in them).

I'm not making any broad conclusions here, just wanted to share the
results of the measurements. For my use case that triggered the
measurements, this tells me I will choose not to use shared top-level
scopes, as the memory requirements and the creation performance
penalty (including the likely higher GC pressure) are acceptable. Your
mileage of course might vary.

(I'm also publishing this for discussion on Google Wave as my first
experiment in actually using it for something; search for "with:public
tag:mozilla rhino" and chime in there if you wish... )

Attila.

--
twitter: http://twitter.com/szegedi

0 new messages