Skip to content

Introduce a new implementation of implicit shadowing#8109

Merged
retronym merged 2 commits intoscala:2.12.xfrom
retronym:topic/rework-implicit-shadower
Jun 24, 2019
Merged

Introduce a new implementation of implicit shadowing#8109
retronym merged 2 commits intoscala:2.12.xfrom
retronym:topic/rework-implicit-shadower

Conversation

@retronym
Copy link
Member

Avoid building up a set of all in-scope implicits during each implicit
search.

Instead, do the filtering of shadowed implicits in a second pass.

retronym added 2 commits May 29, 2019 16:20
Avoid building up a set of all in-scope implicits during each
implicit search.

Instead, do the filtering of shadowed implicits in a second
pass.
With an opt-out system property
@scala-jenkins scala-jenkins added this to the 2.12.9 milestone May 29, 2019
@retronym
Copy link
Member Author

Less ambitious version of #7757 which has proved hard to get over the line.

@retronym retronym requested a review from som-snytt May 29, 2019 06:21
// Collect candidates, the level at which each was found and build a set of their names
var iss = this.iss
while (!iss.isEmpty) {
var is = iss.head
Copy link
Member Author

Choose a reason for hiding this comment

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

While loops avoid ObjectRef-s here for the captured vars.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to lint that after ichoran mentioned how pernicious it is.

@retronym
Copy link
Member Author

retronym commented May 30, 2019

Comparing execution time, again for akka-stream-tests with -Ystop-after:typer. c35194d is the baseline. Time/operation reduced by 0.973x.

(for V in 2.12.9-bin-3d1ab81-SNAPSHOT 2.12.9-bin-c35194d-SNAPSHOT ; do sbt 'set scalaVersion in compilation := "'$V'"' 'hot -psource=@/code/akka/akka-stream-tests/target/akka-stream-tests-test.args -pextraArgs=-Ystop-after:typer -f4'; done)
...
[info] HotScalacBenchmark.compile                     ../corpus           latest  -Ystop-after:typer       false  2.12.9-bin-c35194d-SNAPSHOT  @/code/akka/akka-stream-tests/target/akka-stream-tests-test.args  sample   80  6716.444 ± 56.664  ms/op
[info] HotScalacBenchmark.compile                     ../corpus           latest  -Ystop-after:typer       false  2.12.9-bin-3d1ab81-SNAPSHOT  @/code/akka/akka-stream-tests/target/akka-stream-tests-test.args  sample   80  6535.984 ± 67.920  ms/op

Measuring allocation rate improvements:

$ sbt 'set scalaVersion in compilation := "'$V'"' 'hot -psource=@/code/akka/akka-stream-tests/target/akka-stream-tests-test.args -pextraArgs=-Ystop-after:typer -f1 -prof gc -wi 4 -i 4'
...
[info] HotScalacBenchmark.compile:·gc.alloc.rate.norm                       ../corpus           latest  -Ystop-after:typer       false  2.12.9-bin-c35194d-SNAPSHOT  @/code/akka/akka-stream-tests/target/akka-stream-tests-test.args  sample    4  1654953148.000 ±   10829315.614    B/op
[info] HotScalacBenchmark.compile:·gc.alloc.rate.norm                       ../corpus           latest  -Ystop-after:typer       false  2.12.9-bin-3d1ab81-SNAPSHOT  @/code/akka/akka-stream-tests/target/akka-stream-tests-test.args  sample    4  1496569959.000 ±    5947894.601    B/op

0.90x reduction.

@retronym retronym added the performance the need for speed. usually compiler performance, sometimes runtime performance. label May 30, 2019
@retronym
Copy link
Member Author

Scheduled a community build (link 404 until Seth provides the witticism) on the first commit, which is a bake-off between the old and new implementation that asserts identical results.

/** Sorted list of eligible implicits.
*/
private def eligibleNew = {
final case class Candidate(info: ImplicitInfo, level: Int)
Copy link
Contributor

Choose a reason for hiding this comment

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

  • As a farther step to remove extra allocations, we can unzip the matches array into an Array[ImplicitInfo] and an Array[Int], and thus get rid of the Candidate class.
  • Going farther, and assuming that 255 levels should be enough for anyone, perhaps we could make level into an Array[Byte] ?

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.

4 participants