Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
390 views
in Technique[技术] by (71.8m points)

java - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...