[ https://issues.apache.org/jira/browse/GROOVY-11609?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17947604#comment-17947604 ]
ASF GitHub Bot commented on GROOVY-11609: ----------------------------------------- blackdrag commented on PR #2186: URL: https://github.com/apache/groovy/pull/2186#issuecomment-2833356349 @daniellansun I think that if the logic tries to find duplicates, then because those three caches are not utilized properly. > Avoid finding same variable/class member repeatedly > --------------------------------------------------- > > Key: GROOVY-11609 > URL: https://issues.apache.org/jira/browse/GROOVY-11609 > Project: Groovy > Issue Type: Improvement > Reporter: Daniel Sun > Priority: Major > > When I debugged GROOVY-4721, I found {{VariableScopeVisitor}} will try to > find same variable/class member again and again, the finding logic is quite > complex. Unfortunately, {{VariableScopeVisitor}} is widely used, e.g. > {{ResolveVisitor}}, {{JavaStubCompilationUnit}} and > {{TraitASTTransformation}}. So it's better to avoid finding same > variable/class member repeatedly to gain better performance. > For example, in the following code, {{a}}, {{i}}, {{j}} will be tried to find > many times: > {code} > class BubbleSort { > public static void bubbleSort(int[] a) { > for (int i = 0, n = a.length; i < n - 1; i++) { > for (int j = 0; j < n - i - 1; j++) { > if (a[j] > a[j + 1]) { > int temp = a[j] > a[j] = a[j + 1] > a[j + 1] = temp > } > } > } > } > } > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)