Hi guys
I tried to calculate how much time spend spidermonkey to compile js files at the sturtup of firefox:
So I changed jsapi.api and get the follwing results
Changes made to jsapi (you can see here the hole new version
https://docs.google.com/folder/d/0B9VtjieUwlMDNzJVM3c1UkM0RVE/edit)
Then I recompiled firefox and relaunched it,than I got these results
I calculate three things:
Time needed for only compiling:
JSScript *
JS::Compile(JSContext *cx, HandleObject obj, CompileOptions options,
const jschar *chars, size_t length)
Time needed for comping and encoding:
JSScript *
JS::Compile(JSContext *cx, HandleObject obj, CompileOptions options,
const char *bytes, size_t length)
Time needed for runnig the script:
JS_NEVER_INLINE JS_PUBLIC_API(JSBool)
JS_ExecuteScript(JSContext *cx, JSObject *objArg, JSScript *scriptArg, jsval *rval)
The changes I made:
JSScript *
JS::Compile(JSContext *cx, HandleObject obj, CompileOptions options,
const char *bytes, size_t length)
{
FILE * pFile;
int64_t time = PRMJ_Now();
pFile = fopen ("/home/riadh/jsdata.txt","a");
jschar *chars;
if (options.utf8)
chars = InflateString(cx, bytes, &length, CESU8Encoding);
else
chars = InflateString(cx, bytes, &length);
if (!chars)
return NULL;
JSScript *script = Compile(cx, obj, options, chars, length);
js_free(chars);JS_NEVER_INLINE JS_PUBLIC_API(JSBool)
JS_ExecuteScript(JSContext *cx, JSObject *objArg, JSScript *scriptArg, jsval *rval)
if (pFile!=NULL) {
fprintf(pFile, "compiling and encoding time %s : %.3f ms \n",options.filename, double(PRMJ_Now() - time) / PRMJ_USEC_PER_MSEC);
fclose (pFile);
}
return script;
}
JSScript *
JS::Compile(JSContext *cx, HandleObject obj, CompileOptions options,
const jschar *chars, size_t length)
{
FILE * pFile;
int64_t time = PRMJ_Now();
pFile = fopen ("/home/riadh/jsdata.txt","a");
JSScript * script;
Maybe<AutoVersionAPI> mava;
if (options.versionSet) {
mava.construct(cx, options.version);
// AutoVersionAPI propagates some compilation flags through.
options.version = mava.ref().version();
}
JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, obj);
JS_ASSERT_IF(options.principals, cx->compartment->principals == options.principals);
AutoLastFrameCheck lfc(cx);
script = frontend::CompileScript(cx, obj, NULL, options, chars, length);
if (pFile!=NULL) {
fprintf(pFile, "compiling time %s : %.3f ms \n",options.filename, double(PRMJ_Now() - time) / PRMJ_USEC_PER_MSEC);
fclose (pFile);
}
return script;
}
JS_NEVER_INLINE JS_PUBLIC_API(JSBool)
JS_ExecuteScript(JSContext *cx, JSObject *objArg, JSScript *scriptArg, jsval *rval)
{
JS_PUBLIC_API(JSBool) js;
FILE * pFile;
int64_t time = PRMJ_Now();
pFile = fopen ("/home/riadh/jsdata.txt","a");
RootedObject obj(cx, objArg);
RootedScript script(cx, scriptArg);
JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, obj);
if (cx->compartment != obj->compartment())
*(volatile int *) 0 = 0xf0;
AutoLastFrameCheck lfc(cx);
/*
* Mozilla caches pre-compiled scripts (e.g., in the XUL prototype cache)
* and runs them against multiple globals. With a compartment per global,
* this requires cloning the pre-compiled script into each new global.
* Since each script gets run once, there is no point in trying to cache
* this clone. Ideally, this would be handled at some pinch point in
* mozilla, but there doesn't seem to be one, so we handle it here.
*/
if (script->compartment() != obj->compartment()) {
script = CloneScript(cx, NullPtr(), NullPtr(), script);
if (!script.get())
return false;
} else {
script = scriptArg;
}
js = Execute(cx, script, *obj, rval);
if (pFile!=NULL) {
fprintf(pFile, "execution time : %.3f ms \n", double(PRMJ_Now() - time) / PRMJ_USEC_PER_MSEC);
fclose (pFile);
}
return js;
}
The result are also here
https://docs.google.com/folder/d/0B9VtjieUwlMDNzJVM3c1UkM0RVE/edit.
There is a text file (raw result) and an excel file
I calculate the sums:
The time needed for compiling and encoding is 1550ms
The time needed for running execution is 1245ms
What do you think about that?
If some of you has time, it would be greate if he replace his jsapi.cpp with my jsapi.cpp, (not forget to replace in my jsapi,all the "/home/riadh/jsdata.txt" by the address of the file you would like to save results in it),recompile firefox, open it, then send me your file.
But before that, could you check please if I did a mistake when making this test(I'm newbie to the code, so I can make stupid mistake)
I will use this test to get more data about time spend by spidermonkey (in real website like facebook, google, and websites with jquery)
Cheers
Riadh