New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For loops with -optimize have much worse performance than while loops #4633
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4633?orig=1
|
Matthew Pocock (drdozer) said: |
@Ichoran said: With -optimise, I get timings: while range 1 : -536870912 took 0.339 s demonstrating a 2x-9x slowdown using for instead of while. Without -optimise: while range 1 : -536870912 took 0.337 s gives a 3x-7x slowdown. (These timings are 2.9.0, again Ubuntu 10.10 with Sun Java 1.6.0_24-b07; build 1.7.0-ea-b143 gives similar results.) Incidentally, JRockit (Oracle JRockit(R) (build R28.0.1-21-133393-1.6.0_20-20100512-2126-linux-x86_64, compiled mode) makes it look like the for loop is often as good as the while loop: while range 1 : -536870912 took 0.928 s but of course the dirty little secret here is that even the while loops are horribly slow--everything is 3x worse than it needs to be. |
@ijuma said: |
@ijuma said: |
Ryan Schmitt (ryanls) said: |
Ryan Schmitt (ryanls) said: |
Ryan Schmitt (ryanls) said: |
@adriaanm said: |
@SethTisue said: |
@rklaehn said: https://github.com/rklaehn/si4633 [info] Running ForWhile while range 1 : -536870912 took 0.387 s while range 1 : -536870912 took 0.379 s while range 1 : -536870912 took 0.355 s [info] Running ForWhile while range 1 : -536870912 took 0.369 s while range 1 : -536870912 took 0.369 s while range 1 : -536870912 took 0.371 s |
why is this a separate ticket from #1338? (no reason?) |
This ticket was for the Tiark Challenge, you had to create a ticket with solid numbers in order to get a t-shirt. On the back it said, "Rompf in the Swampf". Previous to that was the Paulp-off. The conversations (including the links here) follow similar twists and turns from quick optimizations to plugins to areas of research. With
Probably additional issues for 2.13 would require a more narrowly-scoped ticket. |
According to Tiark Rompf, "With -optimize, scalac should compile simple for comprehensions to the equivalent of a while loop. If it does not it's a bug (either in the library or in the compiler) and it needs fixing. So if there is indeed a bug, gather solid performance numbers [and] submit a ticket"
Here are performance numbers for loops nested 1, 3, 5, or a variable number of levels deep; in every case, the innermost operation occurs one billion times. The leftmost number is a checksum (the first three should be the same; the fourth is different):
// These are while loops
-1243309312 While1 Elapsed: 0.314 s
-1243309312 While3 Elapsed: 0.301 s
-1243309312 While5 Elapsed: 0.316 s
-17609343 While? Elapsed: 1.151 s
// These are for loops with ranges
-1243309312 Limit1 Elapsed: 0.923 s
-1243309312 Limit3 Elapsed: 0.885 s
-1243309312 Limit5 Elapsed: 2.527 s
-17609343 Limit? Elapsed: 3.308 s
// These use a C-for-like-method that takes an anonymous function
// Note that the JVM gets confused about how to optimize repeated uses
-1243309312 Cfor1 Elapsed: 9.794 s
-1243309312 Cfor3 Elapsed: 0.324 s
-1243309312 Cfor5 Elapsed: 0.450 s
-17609343 Cfor?? Elapsed: 5.662 s
Code is attached.
The text was updated successfully, but these errors were encountered: