4 ms·
This is on the JVM so the JIT's optimizations probably haven't kicked in yet.
by dlurton 7y ago
This is on the JVM so the JIT's optimizations probably haven't kicked in yet.
- banachtarski 7y agoWho are we kidding? Even without JIT optimizations that seems absurdly slow.
- dlurton 7y agoAlso, the PartiQL compiler makes heavy use of closures, each of which becomes a class, so the first time a query executes the JVM has to load a few dozen classes--this probably explains the 86ms more than a lack of JIT optimizations alone.
- pvg 7y agoeach of which becomes a class Wasn't part of the whole thing with lambdas that they don't all become individual classes?
- recursive 7y agoThey're not classes in source code. As an implementation detail, certain compilation strategies do generate them anyway.
- pvg 7y agoWhich ones?
- recursive 7y agoI don't know much about compilers, but basically the ones don't have anywhere else to put the context of a closure.
- pvg 7y agoI don't think that's what happens in the JVM, you can google up the invokevitual + other supporting gunk/mechanism for this.
- recursive 7y agohttps://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.invokevirtual https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.ht... makes plenty of references to dispatching based on class.
- pvg 7y agoD'oh, sorry I sent you on a wild goose chase - you want invokedynamic. Invokedynamic and lambdas.
- jnordwick 7y agothey use invokedynamic instruction so a little more efficient than a class once jit'ed (for hotspot, not sure about the other jvms). there might be some cases where class generation is needed, but i don't think so
- paulddraper 7y agoNo, the point of lambdas is you didn't have to write the full class syntax. Like in other OO languages, every value in Java is an object [1], and every object has a class. [1] Except for the 8 primitive types.
- pvg 7y agoI didn't say that was 'the point of lambdas'. But the lambdas implementation, as far as I know, doesn't make new classes. It's not syntactic sugar around anon/inner classes.
- paulddraper 7y agoYou're right that it's not represented as a class in byte code. At runtime, LambdaMetafactory creates function objects that implement the require interfaces. The objects are instances of java.lang.Object, including returning a value for getClass() that is the same as for any other other lambda objects created from same expression. Not compile time classes, but runtime instances of classes. Uses different machinery with keeping compatibility.