Craig White created GROOVY-8019:
-----------------------------------

             Summary: Strange performance issue using if(true) versus if(1==1)
                 Key: GROOVY-8019
                 URL: https://issues.apache.org/jira/browse/GROOVY-8019
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 2.4.7, 2.4.4
         Environment: Groovy Script Engine in a Java app running on Windows 7 
and Windows Server 2012
            Reporter: Craig White


While using a Groovy script we came across a strange performance anomaly.  
Having the bulk of our script wrapped in an  if( true ){}  statement as opposed 
to an  if( 1==1 ){}  statement severely degrades performance of the inner part 
of the script.  Multi-threaded performance is most severely affected.  There 
appeared to be much more contention running the same script on a 48 core box 
with the  "if(true)".  (took about 100x longer to run 48 copies of these 
scripts on their own threads). 

The curious aspect of this, is that the 'if' statement is not in the nested 
loops, but somehow has negatively affected the compilation / optimization / 
byte-code.

Running a Single copy of this script on a 8 core i7 shows quite a performance 
hit too...  (5000ms vs. 200ms)

The (effective) code to run the script is as follows...

        compiledScript = ((Compilable)engine).compile(scriptString);
        result = compiledScript.eval(bindings);


Here's the script...

// $script_engine_name=groovy

long sum = 0;
double m = 1;

if( true ) {

        System.err.println( "START");
        long t0 = System.currentTimeMillis();

        for( int j=0; j<1000; j++ ) {
          for( int i=0; i<100000; i++ ) {
                sum = sum + i;
                m = m*i;
          }
        }

        long t1 = System.currentTimeMillis();
        System.err.println( "END - " + (t1-t0)+"ms");
}

System.err.println( "Done: "+sum+" "+m );




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to