top | item 41618550

(no title)

the-alchemist | 1 year ago

I believe the term for this is "partial escape analysis" (PEA).

GraalVM is the SOTA in the JVM world for this.

Here's an oldish blog on this: https://chrisseaton.com/truffleruby/seeing-escape-analysis/

I'm sure PEA is better now, but it's not sure if it's moved beyond scalars (int, float, etc.)

discuss

order

vips7L|1 year ago

Wouldn't the lambda here by always escape? It gets created in the function and passed into another one. Looking at the byte code it looks like it always allocates in when its in the interpreter:

    invokedynamic #16,  0             // InvokeDynamic #0:apply:()Ljava/util/function/Function;

amluto|1 year ago

I would expect the relevant optimization to be inlining and/or specialization. An inlined function could allow the JIT detect that the hot path creates and destroys an object without ever using it. Alternatively, if the JIT could specialize the callee for the specific function that is passed in, then the overhead would go away.

(One think I like about less heavily JIT-reliant languages is that it can be more obvious when something will incur a runtime cost.)