Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8019

Strange performance issue using if(true) versus if(1==1)

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.4, 2.4.7
    • Fix Version/s: 2.4.8
    • Component/s: None
    • Labels:
      None
    • Environment:
      Groovy Script Engine in a Java app running on Windows 7 and Windows Server 2012

      Description

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                blackdrag Jochen Theodorou
                Reporter:
                cwhite102 Craig White
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: