Skip to content

SD-226 Be lazier in Fields info transform for better performance#5412

Merged
adriaanm merged 2 commits intoscala:2.12.0from
retronym:ticket/SD-226
Sep 28, 2016
Merged

SD-226 Be lazier in Fields info transform for better performance#5412
adriaanm merged 2 commits intoscala:2.12.0from
retronym:ticket/SD-226

Conversation

@retronym
Copy link
Member

Only mixin fields + accessors into class infos of classes that are
either in the current run, or appear in a superclass chain of a class
in the current run.

This is analagous to what happens in the mixin phase.

Review by @adriaanm

I'll post some benchmark results below.

Only mixin fields + accessors into class infos of classes that are
either in the current run, or appear in a superclass chain of a class
in the current run.

This is analagous to what happens in the mixin phase.
@scala-jenkins scala-jenkins added this to the 2.12.0-RC2 milestone Sep 21, 2016
@retronym
Copy link
Member Author

retronym commented Sep 21, 2016

[info] Benchmark                                           (_scalaVersion)  (extraArgs)  (source)    Mode  Cnt     Score   Error  Units
[info] HotScalacBenchmark.compile                           2.11.8               better-files  sample  742  498.946 ± 1.597  ms/op
[info] HotScalacBenchmark.compile                  2.12.0-6df14e5-SNAPSHOT               better-files  sample  595  625.133 ± 2.822  ms/op
[info] HotScalacBenchmark.compile                  2.12.0-c0450f0-SNAPSHOT               better-files  sample  677  545.357 ± 2.928  ms/op
[info] HotScalacBenchmark.compile                           2.11.8                 scalap  sample  324  1177.065 ± 4.638  ms/op
[info] HotScalacBenchmark.compile                  2.12.0-6df14e5-SNAPSHOT                 scalap  sample  320  1209.683 ± 9.359  ms/op
[info] HotScalacBenchmark.compile                  2.12.0-c0450f0-SNAPSHOT                 scalap  sample  342  1111.957 ± 3.753  ms/op

@retronym
Copy link
Member Author

I have some additional optimizations in https://github.com/scala/scala/compare/2.12.0...retronym:opt/settings?expand=1

which in aggregate improve performance further to:

[info] HotScalacBenchmark.compile                  2.12.0-2ddbc8f-SNAPSHOT               better-files  sample  735  501.089 ± 1.742  ms/op
[info] HotScalacBenchmark.compile                  2.12.0-2ddbc8f-SNAPSHOT                 scalap  sample  360  1047.903 ± 3.885  ms/op

} else tp


case tp@ClassInfoType(parents, oldDecls, clazz) if !needsMixin(clazz) => tp
Copy link
Member Author

@retronym retronym Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this some more, we probably need to guard this with globalPhase.isAfterRefchecks, as we only populate the map of separated compiled superclasses in the refchecks tree transform.

If something at or before refchecks where to run exitingFields(cls.info), we would get here before that map was populated and falsely skip this info transform.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a commit to conservatively approximate this as false.

Copy link
Contributor

@adriaanm adriaanm Sep 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this will fly, since we also need to hit the next case if there's a module or lazy val that needs expansion, for example. <-- scratch that, but would be good to rename needsMixin, since it's more than just about mixing in vals now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to classNeedsInfoTransform

We don't hit this code path during bootstrapping, but we could
conceivably hit it with macros or compiler plugins peering into
the future through atPhase before refchecks as run.

Also rename a method to reflect the generality of the info
transform (it does more than mixin, now.)
@retronym
Copy link
Member Author

retronym commented Sep 27, 2016

I've just repeated some benchmarking after rebasing/restarring on the synchronized performance fix and the other major open PRs:

* 43535e8 Bump to prerelease SBT
* c3c4bba Bump sbt.version to 0.13.12, without breaking
* cb39978 Restarr on faster compiler
*   4aff108 Merge remote-tracking branch 'origin/pr/5419' into merge/2.12-prs
|\
| * e735c34 Avoid needless Boolean.unbox in hot code paths.
| * 0d74b87 Cache setting-derived values, like isScala211, in the Run
*   ab6507a Merge remote-tracking branch 'origin/pr/5412' into merge/2.12-prs
|\
| * e07585c Make isSeparateCompiled... robust against rogue phase time travel
| * c0450f0 SD-226 Be lazier in Fields info transform for better performance
*   a3a8bdb Merge remote-tracking branch 'origin/pr/5397' into merge/2.12-prs
|\
| * e3e1e30 SI-9920 Avoid linkage errors with captured local objects + self types
*   62552f3 Merge remote-tracking branch 'origin/pr/5388' into merge/2.12-prs
|\
| * 5f64ee5 Cast more pro-actively in synthetic accessor trees.
| * 9a39e0c Avoid mismatched symbols in fields phase
* 9212340 Restarr on synchronized fix
* 3ed4496 Merge remote-tracking branch 'origin/pr/5417' into merge/2.12-prs
* e994c1c SD-233 synchronized blocks are JIT-friendly again
Benchmark                                           (_scalaVersion)  (extraArgs)      (source)    Mode  Cnt    Score   Error  Units
HotScalacBenchmark.compile                  2.12.0-ab6507a-SNAPSHOT               better-files  sample  522  468.867 ± 2.662  ms/op
HotScalacBenchmark.compile                  2.12.0-a3a8bdb-SNAPSHOT               better-files  sample  649  570.785 ± 3.450  ms/op
HotScalacBenchmark.compile                  2.12.0-ab6507a-SNAPSHOT                 scalap  sample  249  1004.473 ± 6.369  ms/op
HotScalacBenchmark.compile                  2.12.0-a3a8bdb-SNAPSHOT                 scalap  sample  348  1098.468 ± 6.179  ms/op

After that we still see a big improvement from the laziness here: compile time changes by 0.82x for better-files, 0.91x for scalap.

@adriaanm
Copy link
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants