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

Daniel Sun updated GROOVY-11609:
--------------------------------
    Description: 
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}

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

Reply via email to