Any plans for optimizing engine.eval() ?
Houtman, Roland
Roland.Houtman at nl.yokogawa.com
Thu Sep 25 10:18:59 UTC 2014
Dear Hannes and Sundar,
I've ran with your options.
Regarding what the program is doing is this;
I use one scriptengine instance.
For the tests I create one display shows 200 identical drawing components.
Each component contains 1 CompiledScript instance with its own SimpleContext.
In each Context has a binding named "io" to its own instance of a simple API object with just two methods "input(index)" and "output(index,value)"
Those methods read a value from an Object[] array, and store a value in an Object[] array( thus this is done in java code ).
While the display is showing, every 500 msec, 200 swingworkers (one for each CompiledSCript) are started.
Each swingworker.doInBackground() performs 1 "CompiledScript.eval()" and terminates.
The time is recorded directly before and after the call to "compiledScript.eval()".
The javascript is this: (I use a unique number in hope to avoid caching inside the scriptengine implementation)
var x = <<ID number for each script>>;
var alpha = io.input(0);
alpha = parseInt(alpha) + 32;
if (alpha > 255){
alpha -= 255;
}
io.output( 0, alpha );
io.output( 1, "125.200.200."+alpha );
io.output( 2, x );
What i did to get the below figures;
Each time I used the netbeans "run project" (not 'debug, not profiling')
#1 I opened the display and collected the Duration of the very first run of each 200 scripts. The times you see is the total of these 200 figures.
#2 Then I closed the display and opened it again. (then scripts with the same 'ID number' are generated. The scriptengine maybe reuses cache?)
#3 Then I closed the display and opened it again. (then scripts with the same 'ID number' are generated. The scriptengine maybe reuses cache?)
#4 Then I opened the same display in -new- tab, (then scripts with the *new* 'ID numbers' are generated. Done so that scriptengine can not reuse cache)
Table: each cell shows the total duration of 200 scripts executing the very first time in a display.
#1 #2 #3 #4 VM-ARGS
12116 msec 6814 6000 10064 JDK 1.8 u40 flag : -Dnashorn.args=--global-per-engine
8150 msec 4719 4644 6903 JDK 1.8 u40 flag : '-Dnashorn.args=--optimistic-types=FALSE
11576 msec 2684 5846 6862 JDK 1.8 u40 flag : (both flags)
15371 msec 5448 10308 10892 JDK 1.8 u40 no flags
I hope this is useful in some way.
Thanks,
Roland
>>> --
>>> JDK 1.7u45 CompiledScript.eval() 219 msec
>>> -
>>> JKD 1.8u20 CompiledScript.eval() 13613 msec
>>> JDK 1.8u20 Engine.eval() 14002 msec
>>> -
>>> JDK 1.8.0_40 CompiledScript.eval() 26396 msec
>>> --
More information about the nashorn-dev
mailing list