In my application, I use a huge number of Array (as vector) like this: body1.position = [1,2,3];
This make the GC running very often, and causes big lags in my application.
Is it possible to tell SpiderMonkey to reuse unreferenced array objects instead of create new ones ?
Franck.
No, that's not currently possible.
Mike
Thanks for your response.
But I wondering if there is a way to workaround the lake of recycling :
My first idea is to create a Vector class then :
- detect in a GC callback ( in state JSGC_MARK_END ) Vector objects that are about to be finalized (JS_IsAboutToBeFinalized)
- unmark these Vecor for being GC
- store these object in a list
Later, when I need a new Vector object, I just have to pop it from the list.
My second idea is to create a pool of Vector in a js object ( this create a reference to the object and avoid it from being GC ),
an then, when I need a new (or unused) vector object, I just have to get a Vector from the pool and check if its reference counter is 1.
how to unmark an object from being GC ?
how to get the reference counter of an object ( obj->map->nrefs ?? )
Franck
Objects cannot be resurrected.
If the state that you want to avoid recreating is the private pointer,
then you could recycle that part of it yourself. The creation of the
JSObject itself is typically not very expensive.
> how to get the reference counter of an object ( obj->map->nrefs ?? )
Objects in SpiderMonkey aren't reference counted, so you can't know
the number of references to a given object (though you do know that
it's zero when the object is finalized).
Mike
Or could that be faked or hacked into to spidermonkey easily?
--
---------------------------------------------
Email: chr...@plaidworld.com
iChat / AIM: crack...@mac.com
Plaid World Studios http://www.plaidworld.com
As you do with this code to inject some code inside the VM part
JSString* jsstr;
// if we get errors during error reporting we report those
if ( ((jsstr=JS_NewStringCopyZ(cx, msg)))
&& (JS_AddNamedRoot(cx,&jsstr,"jsstr")) ) {
jsval dummy;
// We can't use JS_EvaluateScript since the stack would be wrong
JSFunction *func;
JSObject* fobj;
const char* fbody="throw new Exception(msg);";
const char* argnames[]={"msg"};
if ((func=JS_CompileFunction(cx, obj, NULL,
1, argnames,
fbody, strlen(fbody),
NULL, 0))) {
// root function
if ( ((fobj = JS_GetFunctionObject(func)))
&& (JS_AddNamedRoot(cx, &fobj, "fobj")) ) {
jsval args[]={STRING_TO_JSVAL(jsstr)};
JS_CallFunction(cx, obj, func, 1, args, &dummy);
JS_RemoveRoot(cx, &fobj);
}
}
JS_RemoveRoot(cx,&jsstr);
Le 16/11/06 8:48, « Chris Dillman » <chr...@plaidworld.com> a écrit :
> Coroutines
body1.position[0] = 1;
body1.position[1] = 2;
body1.position[2] = 3;
which stuffs the existing array with new values rather than replacing it
with a newly created arrray?
- Gordon
-----Original Message-----
From: dev-tech-js-e...@lists.mozilla.org
[mailto:dev-tech-js-e...@lists.mozilla.org] On Behalf Of Mike
Shaver
Sent: Tuesday, November 14, 2006 1:10 PM
To: dev-tech-...@lists.mozilla.org
Subject: Re: recycle array objects instead of GC them
On 11/14/06, franck.fr <spamma...@gmail.com> wrote:
> Hello,
>
> In my application, I use a huge number of Array (as vector) like this:
body1.position = [1,2,3];
> This make the GC running very often, and causes big lags in my
application.
> Is it possible to tell SpiderMonkey to reuse unreferenced array
objects instead of create new ones ?
No, that's not currently possible.
Mike
_______________________________________________
dev-tech-js-engine mailing list
dev-tech-...@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Im not sure I follow...
But are you saing that if I throw an exception.
I can preserve the state of the function I exited and resume later?
Like calling Yield in some languages that support Coroutines?
>JSString* jsstr;
> // if we get errors during error reporting we report those
> if ( ((jsstr=JS_NewStringCopyZ(cx, msg)))
> && (JS_AddNamedRoot(cx,&jsstr,"jsstr")) ) {
> jsval dummy;
> // We can't use JS_EvaluateScript since the stack would be wrong
> JSFunction *func;
> JSObject* fobj;
> const char* fbody="throw new Exception(msg);";
> const char* argnames[]={"msg"};
> if ((func=JS_CompileFunction(cx, obj, NULL,
> 1, argnames,
> fbody, strlen(fbody),
> NULL, 0))) {
> // root function
> if ( ((fobj = JS_GetFunctionObject(func)))
> && (JS_AddNamedRoot(cx, &fobj, "fobj")) ) {
> jsval args[]={STRING_TO_JSVAL(jsstr)};
> JS_CallFunction(cx, obj, func, 1, args, &dummy);
> JS_RemoveRoot(cx, &fobj);
> }
> }
> JS_RemoveRoot(cx,&jsstr);
>
>Le 16/11/06 8:48, « Chris Dillman » <chr...@plaidworld.com> a écrit :
>
>> Coroutines