You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2026/10/20 01:28:01 UTC

[jira] [Closed] (GROOVY-11905) Optimize non-capturing lambdas

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

Paul King closed GROOVY-11905.
------------------------------

> 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)