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

[jira] [Updated] (GROOVY-7473) ineffient code generation

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

Eric Milles updated GROOVY-7473:
--------------------------------
    Description: 
Groovy 2.4.3 generates not the most efficient byte code of a simple statement like "in".

e.g. The following statement:
{code:groovy}
if object.stringProperty in ["State1", "State2", "State3"
{code}
gets complied in:
{code:java}
if (DefaultTypeTransformation.booleanUnbox((ScriptBytecodeAdapter.createList(new Object[] { "State1", "State2", "State3" }) == null ? 1 : 0) != 0 ? Boolean.valueOf(object.getStringProperty() == null) : Boolean.valueOf(DefaultGroovyMethods.isCase(ScriptBytecodeAdapter.createList(new Object[] { "State1", "State2 ", "State3" }), object. getStringProperty ()))))
{code}
instead of this a more efficient construct would be the usage of an static list
e.g.
{code:java}
static List<String> l1;
static {
        l1 = new LinkedList<String>();
        l1.add("State1");
        l1.add("State2");
        l1.add("State3");
}

if (DefaultTypeTransformation.booleanUnbox((l1 == null ? 1 : 0) != 0 ? Boolean.valueOf(object.getStringProperty() == null) : Boolean.valueOf(DefaultGroovyMethods.isCase(l1, object. getStringProperty ()))))
{code}

  was:
Groovy 2.4.3 generates not the most effient byte code of a simple statement like "in".

e.g. The following statement:
If object.stringProperty in ["State1", "State2", "State3"

gets complied in:
if (DefaultTypeTransformation.booleanUnbox((ScriptBytecodeAdapter.createList(new Object[] { "State1", "State2", "State3" }) == null ? 1 : 0) != 0 ? Boolean.valueOf(object.getStringProperty() == null) : Boolean.valueOf(DefaultGroovyMethods.isCase(ScriptBytecodeAdapter.createList(new Object[] { "State1", "State2 ", "State3" }), object. getStringProperty ()))))

instead of this a more effient construct would be the usage of an static list
e.g.
static List<String> l1;
static {
        l1 = new LinkedList<String>();
        l1.add("State1");
        l1.add("State2");
        l1.add("State3");
}

if (DefaultTypeTransformation.booleanUnbox((l1 == null ? 1 : 0) != 0 ? Boolean.valueOf(object.getStringProperty() == null) : Boolean.valueOf(DefaultGroovyMethods.isCase(l1, object. getStringProperty ()))))




> ineffient code generation
> -------------------------
>
>                 Key: GROOVY-7473
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7473
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.3
>            Reporter: Laurenz Tontsch
>            Assignee: Eric Milles
>            Priority: Major
>              Labels: performance
>             Fix For: 4.0.0-rc-1
>
>
> Groovy 2.4.3 generates not the most efficient byte code of a simple statement like "in".
> e.g. The following statement:
> {code:groovy}
> if object.stringProperty in ["State1", "State2", "State3"
> {code}
> gets complied in:
> {code:java}
> if (DefaultTypeTransformation.booleanUnbox((ScriptBytecodeAdapter.createList(new Object[] { "State1", "State2", "State3" }) == null ? 1 : 0) != 0 ? Boolean.valueOf(object.getStringProperty() == null) : Boolean.valueOf(DefaultGroovyMethods.isCase(ScriptBytecodeAdapter.createList(new Object[] { "State1", "State2 ", "State3" }), object. getStringProperty ()))))
> {code}
> instead of this a more efficient construct would be the usage of an static list
> e.g.
> {code:java}
> static List<String> l1;
> static {
>         l1 = new LinkedList<String>();
>         l1.add("State1");
>         l1.add("State2");
>         l1.add("State3");
> }
> if (DefaultTypeTransformation.booleanUnbox((l1 == null ? 1 : 0) != 0 ? Boolean.valueOf(object.getStringProperty() == null) : Boolean.valueOf(DefaultGroovyMethods.isCase(l1, object. getStringProperty ()))))
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)