Subj : [SpiderMonkey] prototypes and millions of objects To : netscape.public.mozilla.jseng From : Brian Barnes Date : Sat May 15 2004 02:29 am A couple of people are starting to use my 3D engine (which uses SpiderMonkey for scripting.) They've gone way beyond my original demos, and they have thousands of objects loaded into the engine. This, of course, takes forever to create and eats up a lot of runtime memory. Each "item" in the map has a corresponding js object, which has a bunch of children objects. If you have 500 items in a map, you could easily have 5000 objects in the engine. So, since each of these items has the exact same object model, prototypes would be good. Question #1: My engine depends on private data from the objects to work right. If I have a prototype, and I get a set or get property call, will I get the private data from the object or from the prototype (the property will be on the prototype.) If it's the prototype, then I can't use them :( Question #2: As I'm experimenting, I noticed something. I do this little trick where each class I use I override the "add property" stub, and if a flag tells me I'm in creation, then to let adds go through. Otherwise, fail them. This turns off people's ability to add to my objects. This doesn't work when using prototypes because if I use the same class for the prototype as I do the real object, the real object triggers this add before actually checking the prototype for the property! Is this some optimization? Question #3: When creating the "real" object (using JS_DefineObject) from the prototype, do I need to really set any class since that class is all set in the prototype? Could I use a stubed class (or null, for that matter?) that might solve #2. [>] Brian .