[
https://issues.apache.org/jira/browse/GROOVY-11905?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18072954#comment-18072954
]
ASF GitHub Bot commented on GROOVY-11905:
-----------------------------------------
Copilot commented on code in PR #2438:
URL: https://github.com/apache/groovy/pull/2438#discussion_r3069450630
##########
src/main/java/org/codehaus/groovy/ast/ClassNode.java:
##########
@@ -1452,17 +1452,21 @@ public ClassNode getOuterClass() {
return null;
}
+ private List<ClassNode> outerClasses;
public List<ClassNode> getOuterClasses() {
+ List<ClassNode> ocs = outerClasses;
+ if (ocs != null) return ocs;
+
ClassNode outer = getOuterClass();
if (outer == null) {
- return Collections.emptyList();
+ return outerClasses = Collections.emptyList();
}
List<ClassNode> result = new ArrayList<>(4);
do {
result.add(outer);
} while ((outer = outer.getOuterClass()) != null);
- return result;
+ return outerClasses = Collections.unmodifiableList(result);
Review Comment:
`getOuterClasses()` now caches the computed list in a field, but the
implementation doesn’t account for redirect/proxy `ClassNode`s. Since
`setRedirect(...)` can be called later for non-primary nodes, a proxy may cache
`Collections.emptyList()` (or an outdated chain) before redirect is set/changed
and then return stale results thereafter. Consider delegating to
`redirect().getOuterClasses()` when `redirect != null` and/or clearing
`outerClasses` in `setRedirect(...)` to keep the cache correct.
> 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)