-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Range.foreach is not specialised #19759
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
Comments
Simple programs like that are not remotely good enough to reliably test performance on the JVM. Please use JMH when attempting to compare run-time performance on the JVM. |
actually the answer is very clear, Scala 2.13 specialised |
looking at cfr-decompiler output difference long s2 = System.nanoTime();
- RichInt$.MODULE$.until$extension(Predef$.MODULE$.intWrapper(0), M).foreach$mVc$sp((Function1)(JFunction1.mcVI.sp & Serializable)x$1 -> {
+ RichInt$.MODULE$.until$extension(Predef$.MODULE$.intWrapper(0), M).foreach((Function1)(JFunction1.mcVI.sp & Serializable)_$1 -> {
for (int i = 0; i < N; ++i) {
sum$1.elem += arr[i];
}
|
(jinx..) |
Thanks, @bishabosha |
actually the clearer answer is that Scala 3 doesn't do Showing original in-module (the b version) vs factored out to instance method:
The original is the |
I must have mixed things up yesterday, i thought I could reproduce it with a
So it still seems worth fixing. |
I removed the |
I have asked a question in https://contributors.scala-lang.org/t/status-of-specialization-in-scala-3/4628 and my impression from the response was there is no support at all for specialization in Scala 3. I know Scala 3 certainly cannot produce specialized code. Is it able to consume specialized functions created in Scala 2, or how can this issue be fixed? |
@OndrejSpanel Yes, it should be able to consume specialized functions created in Scala 2. So it seems there's an issue with that specialization that needs fixing. |
Compiler version
I've compared a simple peace of code performance running with Scala 2 and Scala 3 and faced with performance regression. In this case Scala 2 generated program is more than 7 times faster on my computer.
The code is just calculate sum of big Array[Long] several times.
Minimized code
The whole project code is available here: https://github.com/limansky/perf-issue
Output
Expectation
I suppose Scala 3 should be at least as fast as Scala 2.
The text was updated successfully, but these errors were encountered: