Question on Caching and Thank You

A. Sundararajan sundararajan.athijegannathan at oracle.com
Mon Apr 20 13:05:29 UTC 2015


You could create and reuse javax.script.CompiledScript instances on the 
same engine instance. That should work for you.

-Sundar

On Saturday 18 April 2015 08:32 PM, Tony Zakula wrote:
> Hey All,
>
> First off let me thank the Nashorn team for all the work on performance.
> The latest is extremely awesome and impressive to say the least.  I have
> been working on a project to see if the same performance could be achieved
> by replacing a custom JSP system with a JS template system leveraging
> Nashorn, and I think it is just about there.
>
> I just had a quick question on caching.  We are creating our engine for use
> on multiple threads with something like the following:
>
> System.setProperty("nashorn.typeInfo.maxFiles", "20000");
> final ScriptEngine engine = new
> NashornScriptEngineFactory().getScriptEngine(new String[] {"-ccs=500",
> "-ot=true"});
>
> and we will try the "-pcc" soon.
>
> We use a JS written template system.  We compile the template to JS code in
> JS and the cache it in a Java Map that is available to all scripts on all
> threads.  When a template is included, we use the compiled template from
> the Java Map and use *eval* to run the template.  Since the template is
> always the same until it is changed, my assumption is Nashorn compiles and
> caches it for reuse.
>
> My questions is, what is the best way to leverage the caching?  Is eval
> fine?  Or should we potentially save the compiled JS templates to disk and
> then load them with the load command or URL to achieve better performance?
>
> Thanks,
>
> Tony



More information about the nashorn-dev mailing list