Skip to content

Nashorn performance? Just use default settings and very few engines

September 22, 2015

tldr; Use only one script engine in your Nashorn app and don’t try parameters for persistent code cache or optimistic typing: No use really.

Reading Pieroxy’s article on the comparison of JS engines for Java I missed those other parameters (-pcc, -ot…) for Nashorn. So here are the results:

Scales are seconds over iterations (200).

Optimistic types kills startup time


All options arrive at the same times in the end

Optimistic type info speeds up optimization in the mid-game – but beware that it slows first runs considerably, with or without nashorn.typeInfo.maxFiles cache option. Persistent code cache (-pcc, the blue line), doesn’t really help.

System.setProperty("nashorn.typeInfo.maxFiles", "20000");


The hidden iceberg when evaluating the warmup is that it uses a lot of cpu cores. Here are the CPU times:


Here a benefit of the optimistic type cache is visible (cpu ot maxFiles) – but only in the mid-game and only for a moment.


I also tried to find benefits of optimistic type cache and persistent code cache when using multiple engines, but couldn’t find any. A new engine still needs to warmup, see four cases here (with/without optimistic typing and creating the second engine before using the first or after having used the first for 30 iterations – there’s never a big benefit to the new engine):



Comparison of 1.8u51 and 1.8u60

u60 seems to get less benefit from the type info cache during mid-game, but otherwise shows pretty similar results.

u60_real_optimization u60_cpu_optimization


Optimization takes it’s sweet time and the real hero is Node (see Pieroxy’s article), which is amazing right from the first iteration. For Java it’s Nashorn now, but only partially for performance reasons, more on that in another post.

Test info

Nashorn created a persistent code cache of 4.3 MB in the work dir of the test and 1 MB of type info cache in ~/Library/Caches/ .

Test setup: 2.4 GHz dual core (HT) 2011 Macbook with SSD, JDK 1.8u51 and 1.8u60 .

Code: Possibly later.

Nashorn performance review data spreadsheet (with many more runs than in here).

Update on Dec 29th 2015:
Improved the images on the second engine warmup problems.

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s