[ 
https://issues.apache.org/jira/browse/GROOVY-11905?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18073888#comment-18073888
 ] 

ASF GitHub Bot commented on GROOVY-11905:
-----------------------------------------

paulk-asert commented on PR #2438:
URL: https://github.com/apache/groovy/pull/2438#issuecomment-4258391068

   +1, here is Claude's assessment (details in the link):
   
   Code: Well-designed separation of Analyzer and Writer. The GeneratedLambda 
record and MetaDataKey enum are quality improvements. Test coverage is 
excellent (50+ tests). Main risks are AST in-place mutation and 
     potential false positives in capture detection.                            
                                                                                
                                                       
                                                                                
                                                                                
   
                                                      
     Performance: No regression detected. No improvement visible either, but 
that's expected 

> Optimize non-capturing lambdas
> ------------------------------
>
>                 Key: GROOVY-11905
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11905
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Daniel Sun
>            Priority: Major
>
> *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