How to precompile SpiderMonkey code for faster execution? -
i using code this:
js_evaluatescript(context, global,"go_back('blabla')", 17, "", 1, &r);
to call go_back()
, in context
. extremely slow, , think because string have compiled each time.
i try find way call same piece of code many times in fast way, without recompilation, or object creation each time. mozilla docs , sources not organized way, there reference, , need know every function before can make choice.
so hints? best practice this?
jsfunction * func = 0; static jsbool my_native(jscontext *cx, uintn argc, jsval *vp) { jsval r = jsval_false; if (func == 0) { const char *args[1] = {"s"}, *src = "go_back(s)"; func = js_compilefunction(cx, 0, 0, 1, args, src, 10, "", 0); } js_callfunction(cx, 0, func, 1, &r, &r); return js_true; }
this fast (20 times in example), compared js_evaluatescript
. note code simplified, still need pass string
argument somehow. (i not sure myself how that.) , may need js_reportpendingexception()
go_back()
can fail.
Comments
Post a Comment