-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Performance downgrade of Range.foreach compared to Scala2 #13402
Comments
This is a failure of specialization. Maybe @liufengyun has an idea why it fails, given he implemented #10452. |
This is because we only implement function specialization, but not method specialization and class specialization. For this particular example, method specialization will ensure that the call Method specialization and class specialization are up to debate, due to their complications (Method specialization is of less concern compared to class specialization). In Scala 3, marking As a side note, JVM inlining & optimization seem to be not good enough in the presence of lambdas. The loss of the optimization opportunity might be related to the complex underlying mechanism for creating and representing lambdas. |
Duplicate of #8880 |
Reimplementing method specialization is not trivial and not necessarily simpler than some of the alternatives discussed in #8880, in any case what's missing here is someone to take charge of finding a solution to the problem. |
To help us folks who are just zooming past, can someone show how the code looks like when it is using the right form of specialisation? |
Compiler version
Scala3: 3.0.0, 3.0.1
Scala2: 2.13.0
JVM: openjdk 11.0.9.1
Scalameter: 0.21
Minimized code
Output
while loop benchmark is roughly comparable, there is a massive downgrade in performance for Range.
I decompiled the code using IntelliJ
Scala2:
Scala3:
And javap output:
Scala2:
Scala3:
Conclusions
Scala2 uses Range.foreach$mVc$sp
Scala3 uses Range.foreach
See https://www.javadoc.io/doc/org.scala-lang.modules/scala-java8-compat_2.11/0.8.0-RC1/scala/runtime/java8/JFunction1$mcVI$sp.html#apply:DmcVI:Dsp-int-
Original SO post:
https://stackoverflow.com/questions/68941194/range-benchmark-sluggish-after-migrating-to-scala3
Expectation
Performance of Scala3 code is on par with Scala2
The text was updated successfully, but these errors were encountered: