Presentation is loading. Please wait.

Presentation is loading. Please wait.

Axel Faust Senior IT-Consultant / Software Architect PRODYNA AG

Similar presentations


Presentation on theme: "Axel Faust Senior IT-Consultant / Software Architect PRODYNA AG"— Presentation transcript:

1 Axel Faust Senior IT-Consultant / Software Architect PRODYNA AG
From Rhino to Nashorn Axel Faust Senior IT-Consultant / Software Architect PRODYNA AG

2 Proof of concept Part of Enhanced Script Environment
Replace Rhino with Nashorn Explore potential improvements 1

3 Rhino Rhino Since Alfresco 1.3 ECMA-262 Ed. 3 (1999) 2

4 Rhino vs. Nashorn Rhino Nashorn / JDK 8 Since Alfresco 1.3
ECMA-262 Ed. 3 (1999) Nashorn / JDK 8 ECMA-262 Ed. 5.1 (2011) 3

5 Nashorn benefits Performance invokedynamic Dynamic linking (cached)
Persistent script caching 4

6 Nashorn benefits How much faster? My micro-benchmarks (YMMV)
ms (10k runs) Each benchmark consists of 10k engine warmup and 10k timed executions Trivial JS - JS source code: var a = 3, b = 8, result; result = Math.pow(a, b); Interop: JS source code: var a = 3, b = 2.5, c = 'String', idx, max = 100; for(idx = 0; idx < max; idx++) { obj.testCall(a + idx, b, c);} Java class: 3 overloaded methods => boolean testCall(double, double, String) - boolean testCall(int, double, String) - boolean testCall(Number, Number, String) Java method: trivial => return a == b || c.equals("String"); 5

7 Nashorn benefits How much faster? My micro-benchmarks (YMMV)
ms (10k runs) Each benchmark consists of 10k engine warmup and 10k timed executions Trivial JS - JS source code: var a = 3, b = 8, result; result = Math.pow(a, b); Interop: JS source code: var a = 3, b = 2.5, c = 'String', idx, max = 100; for(idx = 0; idx < max; idx++) { obj.testCall(a + idx, b, c);} Java class: 3 overloaded methods => boolean testCall(double, double, String) - boolean testCall(int, double, String) - boolean testCall(Number, Number, String) Java method: trivial => return a == b || c.equals("String"); 6

8 Nashorn benefits SAM / lambda support
removeIf => Collection default method (JDK8) page.url.args.keys().removeIf(function(key) { var isEmptyArg = page.url.args[key] === null || page.url.args[key].length === 0; return isEmptyArg; }); 7

9 Nashorn benefits Improved native primitive handling
E.g. jsString === javaString Collection handling List + Map = native(-ish) Conversion util 8

10 Nashorn benefits Security Integrated with Security Manager
Script-specific security policies 9

11 Primary challenge Rhino is virtually everywhere 10

12 Primary challenge Rhino is virtually everywhere
Value objects and services 11

13 Primary challenge Rhino is virtually everywhere
Value objects and services Execution context and scope 12

14 Primary tools Sub-class proxies Value conversion Adapter functionality
Virtually identical API Value conversion E.g. NativeArray Rhino <=> Nashorn 13

15 JSObject ~= Scriptable (special interop interface)
JSObject proxy JSObject ~= Scriptable (special interop interface) ScriptNode JSObject Mixin JSObject cglib (sub-class) 14

16 JSObject ~= Scriptable (special interop interface)
JSObject proxy JSObject ~= Scriptable (special interop interface) ScriptNode JSObject Mixin JSObject cglib (sub-class) Value Converter JSObject Mixin Method lookup and param conversion Scope + Context Mixin Result conversion JS ScriptNode JS 15

17 Other migration tools Bytecode instrumentation: Remove „final“
Signature mapping (specialization) Input for value conversion 16

18 Status „Migrated“ Repository-tier (4.2.f) Capable of running Share
Custom import API ( importScript() ) Enhanced logging Capable of running Share Dashboards / DocLib / Sites Read / Write 17

19 In the Future Migrate existing tools (i.e. batch processor)
Evaluate debugability „Migrate“ Share? 18

20 Open issues - Nashorn Customizability Performance guides
== / === based on equals() Locale + time zone handling Performance guides 19

21 Open issues - Alfresco Script API refactoring Clean up legacy scripts
Agnostic interfaces Abstract functional aspects Clean up legacy scripts 20

22 Resources Thanks to @sundararajan_a (Twitter support)
Nashorn (OpenJDK project) GitHub (nashorn_PoC branch)


Download ppt "Axel Faust Senior IT-Consultant / Software Architect PRODYNA AG"

Similar presentations


Ads by Google