Skip to content

Reduce overhead of enabling -Ystatistics #6234

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

Merged
merged 1 commit into from
Dec 20, 2017
Merged

Conversation

retronym
Copy link
Member

The implementation trick of using an AlmostFinalValue to have zero
cost for the "isEnabled" check in the common case has a small flaw:
the switchpoint is tripped every time stats is enabled, rather
than just on the first time. This discards a swathe of JIT compiled
code each time a Global is started with -Ystatistics.

This commit avoids tripping the switchpoint redundantly.

Performance:

⚡ for extra in "-Ystatistics:_" ""; do for v in 2.12.5-bin-91649d1-SNAPSHOT 2.12.4; do echo $v $extra; sbt 'set scalaVersion in compilation := "'$v'"' 'hot -psource=scalap -f1 -wi 5 -i 3 -pextraArgs='$extra | egrep 'HotScalacBenchmark.compile\s'; done; done
2.12.5-bin-91649d1-SNAPSHOT -Ystatistics:_
[info] HotScalacBenchmark.compile                          a8c43dc  -Ystatistics:_       false    scalap  sample   33   973.523 ± 23.389  ms/op
2.12.4 -Ystatistics:_
[info] HotScalacBenchmark.compile                          a8c43dc  -Ystatistics:_       false    scalap  sample   12  2921.333 ± 177.831  ms/op
2.12.5-bin-91649d1-SNAPSHOT
[info] HotScalacBenchmark.compile                          a8c43dc                    false    scalap  sample   38  811.846 ± 13.436  ms/op
2.12.4
[info] HotScalacBenchmark.compile                          a8c43dc                    false    scalap  sample   38  820.814 ± 17.809  ms/op

There is still more overhead than I would like, and it might still make
sense to move a few stats back into the "hot" category.

The implementation trick of using an AlmostFinalValue to have zero
cost for the "isEnabled" check in the common case has a small flaw:
the switchpoint is tripped _every_ time stats is enabled, rather
than just on the first time. This discards a swathe of JIT compiled
code each time a Global is started with `-Ystatistics`.

This commit avoids tripping the switchpoint redundantly.

Performance:

```
⚡ for extra in "-Ystatistics:_" ""; do for v in 2.12.5-bin-91649d1-SNAPSHOT 2.12.4; do echo $v $extra; sbt 'set scalaVersion in compilation := "'$v'"' 'hot -psource=scalap -f1 -wi 5 -i 3 -pextraArgs='$extra | egrep 'HotScalacBenchmark.compile\s'; done; done
2.12.5-bin-91649d1-SNAPSHOT -Ystatistics:_
[info] HotScalacBenchmark.compile                          a8c43dc  -Ystatistics:_       false    scalap  sample   33   973.523 ± 23.389  ms/op
2.12.4 -Ystatistics:_
[info] HotScalacBenchmark.compile                          a8c43dc  -Ystatistics:_       false    scalap  sample   12  2921.333 ± 177.831  ms/op
2.12.5-bin-91649d1-SNAPSHOT
[info] HotScalacBenchmark.compile                          a8c43dc                    false    scalap  sample   38  811.846 ± 13.436  ms/op
2.12.4
[info] HotScalacBenchmark.compile                          a8c43dc                    false    scalap  sample   38  820.814 ± 17.809  ms/op
```

There is still more overhead than I would like, and it might still make
sense to move a few stats back into the "hot" category.
@scala-jenkins scala-jenkins added this to the 2.12.5 milestone Dec 19, 2017
@retronym retronym requested a review from jvican December 19, 2017 22:42
@jvican jvican merged commit 3792784 into scala:2.12.x Dec 20, 2017
@jvican
Copy link
Member

jvican commented Dec 20, 2017

Damn! I’m sorry my new iPhone got crazy and I mistakenly pressed “Merge pull request” when I wanted to say LGTM. Sorry for that — if someone takes any issue wIth the PR please feel free to revert and submit the PR again.

jvican added a commit to scalacenter/scalac-profiling that referenced this pull request Jan 13, 2018
The latest scalac master includes
scala/scala#6234 which makes the overhead of
statistics smaller.
@retronym retronym added the performance the need for speed. usually compiler performance, sometimes runtime performance. label Feb 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance the need for speed. usually compiler performance, sometimes runtime performance.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants