Polyglot language interoperation
Performance Anti-Patterns |
---|
Convenor: Ben Evans |
Participants:
|
Summary:
Fact: Interopability is hard Why? Source is compiled to class (bytecode) clojure one class per method fn: -> fn$1134 What is hard?
Just looking at method dispatch Java Dispatch...
Virtual Method Call: 1. Mark 2. Pointer to class having list of pointers to methods (v-table), get the offset walk the inheritance Other language: $obj->$method(); Starting with reflection you end up with not typesafe method description. Java 7 introduces a type safe way: MethodType.methodType(retType, paramTypes) MethodHandles: Lookup -findVirtual(MethodType...) -getStatic -... results in MethodHandle mh mh.invoke(...); => unreflection is possible... Using MethodHandles can improve the performance:
Inheritance: Ruby: Everything is an IRubyObject (The IRubyObject Approach) myObj = (IRubyObject) registry.get(...) Scala: has Any and AnyRef, no common super type to cast to What you really need:
Biconversion: java.lang.interop
Project DYNALINK (Attila Szegedi) |
Recommendations:
(as above) |