Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Nashorn startup slowness be overcome?

I've used Rhino for a scripting component inside graphics. In the project there are about 200 small scripts running independantly. Immediately when starting the application the scripts should be at full speed. Rhino's performance was sufficient, but since Oracle advices to migrate to Nashorn, i'm facing a dilema.

Below a picture showing the load difference between Rhino and Nashorn at approximayely 15,000 invocations of the scripts. The Startup slowness of Nashorn is my biggest issue.

Note, this was back on JDK 1.8.0. JDK 1.8u5 is similar

Engine performance compared

I hope the picture is clear.

This is an outline of how i use the ScriptEngine:

  • I'm using One scripting Engine instance,
  • i create a CompiledScript object for each script,
  • A Swingworker executes a CompiledScript.eval() once.
  • Every half second the SwingWorkers are started.
  • Each CompiledScript has its own SimpleScriptContext instance which is reused for every execution.

Below i included a runtime profile of how busy the engine is over time; enter image description here

Does anyone know how to overcome the startup slowness of Nashorn?


UPDATE 15 April '15
Ran the same test with 200 seperate scripts on Java8u45.
Performance is much better! Runs similarly fast as Rhino on Java7.

like image 436
Houtman Avatar asked Sep 12 '14 14:09

Houtman


Video Answer


1 Answers

On Java 1.8, you can use Rhino via the javax.script API by using this Maven dependency and requesting the engine rhino:

    <dependency>
        <groupId>de.christophkraemer</groupId>
        <artifactId>rhino-script-engine</artifactId>
        <version>1.1.1</version>
    </dependency>

Home page here: https://github.com/cevou/rhino-script-engine

Binaries: here

If you want the very latest version of Rhino, you can override it by adding something like this:

    <dependency>
        <groupId>org.mozilla</groupId>
        <artifactId>rhino</artifactId>
        <version>${rhinoVersion}</version>
    </dependency>

Binaries: here

Incidentally, if you want to use get the latest Rhino on Java 1.7 via javax.script, you should request the engine name rhino17R5 or you might randomly get an instance of the old Rhino which is part of the JRE. The exact engine name required depends on the version of rhino-script-engine. For 1.1.1, it is rhino17R5.

like image 182
seanf Avatar answered Sep 27 '22 22:09

seanf