Comparing Performance of GraalJS vs Nashorn

In previous posts, I have shown you how to execute Javascript in JVM using Nashorn & GraalJS. GraalJS performance variation across interpreted and compiled mode is also compared in the post here: Comparing performance of GraalJS interpreted vs compiled mode.

With Nashon not part of Java from version 14 onwards and GraalJS availability, let’s now compare the performance of Javascript execution in Nashorn against the GraalJS executing in interpreted mode. I have used the same benchmark program and ran the comparison in laptop running AMD Ryzen 5 2500U (8 CPU) using GraalVM (version 21) with single thread. Here are the results.

Nashorn

Average time, Latency

IterationForked VM 1Forked VM 2
173.24273.475
262.90462.604
360.45760.415
457.17458.324
554.91753.681
652.36555.873
755.10454.938
853.56353.134
953.71955.183
1052.24951.822
Nashorn – Time per Operation (Average time) in Milliseconds

Throughput

IterationForked VM 1Forked VM 2
113.66413.52
216.39716.474
316.68516.42
418.09917.971
518.39917.529
618.1418.369
718.66118.689
818.25719.069
919.16318.85
1019.41819.182
Nashorn – Throughput (Operations per Second)

Comparison

Average Time (ms/op)MinimumAverageMaximum
GraalJS Interpreted32.34532.80833.498
Nashorn51.82253.79555.873
Throughput (Ops/Sec)MinimumAverageMaximum
GraalJS Interpreted30.73831.32131.779
Nashorn18.14018.78019.418

The performance of GraalJS in interpreted mode is 1.5 times better than Nashorn. But performance results are based on multiple factors, and we know that the benchmark program used is CPU-bound. and this may not reflect the characteristics of our real-world applications. Having known that the Nashorn is not anymore officially part of Java delivery and GraalJS is providing better performance, engineering management have to do the trade-off decision before investing in migration from Nashorn to GraalJS.

Stay tuned.