Nashorn performance? Just use default settings and very few engines
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.
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.
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.
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/com.oracle.java.NashornTypeInfo .
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.