[
https://issues.apache.org/jira/browse/GROOVY-8019?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King closed GROOVY-8019.
-----------------------------
> 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.4, 2.4.7
> Environment: Groovy Script Engine in a Java app running on Windows 7
> and Windows Server 2012
> Reporter: Craig White
> Assignee: Jochen Theodorou
> Fix For: 2.4.8
>
>
> 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...
> {code}
> compiledScript = ((Compilable)engine).compile(scriptString);
> result = compiledScript.eval(bindings);
> {code}
> Here's the script...
> {code}
> // $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 );
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)