KB Article #178597

Performance impact of using Rhino vs. Nashorn as the JavaScript Engine

Problem

Starting in API Gateway 7.4.1, two different JavaScript engines, Rhino & Nashorn are available for use in Scripting Language filters. What is the difference between them and is there any performance impact from using one or the other?

Resolution

This is due to a change Oracle made starting in JRE 1.8, which is used by 7.4.1 and later. Prior to that, Rhino was the native JavaScript engine. Now, Nashorn is the native JavaScript engine and Rhino support comes from a slower, add-on Rhino JAR from Mozilla that was necessary to maintain backwards compatibility due to the fact that the two engines use different syntax.


However, this backwards compatibility comes with a significant performance cost because the Rhino support is no longer native to Java. Users upgrading from prior versions may see a performance impact if they do not convert their scripting language filters to use the newer Nashorn scripting language engine. Because of this, new development should use the Nashorn engine exclusively and any scripts using the Rhino engine should be evaluated for any performance impact and converted to Nashorn if necessary.


More information on the changes required to convert from one engine to the other can be found in the Rhino Migration Guide on the OpenJDK wiki. Oracle also offers a page on the Nashorn Java API.