[ 
https://issues.apache.org/jira/browse/GROOVY-11905?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniel Sun resolved GROOVY-11905.
---------------------------------
    Fix Version/s: 6.0.0-alpha-1
         Assignee: Daniel Sun
       Resolution: Fixed

> Optimize non-capturing lambdas
> ------------------------------
>
>                 Key: GROOVY-11905
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11905
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Daniel Sun
>            Assignee: Daniel Sun
>            Priority: Major
>             Fix For: 6.0.0-alpha-1
>
>
> *Problem* Previously, every non-capturing lambda call site incurred 
> unnecessary allocation overhead. The compiler would:
>  # Generate a {{Closure}} wrapper instance via {{NEW}} + 
> {{{}INVOKESPECIAL{}}}.
>  # Pass it as a captured argument to the {{invokedynamic}} instruction.
> This forced {{LambdaMetafactory}} to generate a new proxy instance per 
> invocation, completely defeating JVM singleton optimizations.
> *Solution* For non-capturing lambdas (no shared variables, no instance member 
> access), we now align the compilation strategy with Java's behavior by 
> eliminating the capture phase. The new emitted bytecode features:
>  * A {{static}} modifier on the generated {{doCall}} method.
>  * A capture-free {{invokedynamic}} instruction with the descriptor 
> {{{}()LFunctionalInterface;{}}}.
>  * An {{H_INVOKESTATIC}} method handle pointing directly to the static 
> {{{}doCall{}}}.
> *Impact*
>  * {{LambdaMetafactory}} now creates and caches a singleton instance, 
> returning a {{{}ConstantCallSite{}}}.
>  * Achieves *zero-allocation* at the call site for non-capturing lambdas.
>  * Matches standard Java execution behavior, significantly reducing GC 
> footprint.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to