Skip to content

Commit 32b4e1c

Browse files
committed
Optimize megaphase
#3366 did lose some performance relative to the previous tree transform scheme. http://dotty-bench.epfl.ch/3366/ shows a loss of about 4% for scalapb and dotty. This commit is trying to get it back, using two tweaks: - We don't call an empty context or node transformer, instead we represent such transformers now by null and return immediately if we hit a null transformer - After a transform, we do a test whether we still have a tree of the same tag before computing the treeTag of the transformed tree. This avoids the megamorphic dispatch in the common case where the tag is the same.
1 parent 26aba2b commit 32b4e1c

File tree

3 files changed

+307
-82
lines changed

3 files changed

+307
-82
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ class Compiler {
9797
List(new LinkScala2Impls, // Redirect calls to trait methods defined by Scala 2.x, so that they now go to their implementations
9898
new LambdaLift, // Lifts out nested functions to class scope, storing free variables in environments
9999
// Note: in this mini-phase block scopes are incorrect. No phases that rely on scopes should be here
100-
new ElimStaticThis), // Replace `this` references to static objects by global identifiers
100+
new ElimStaticThis), // Replace `this` references to static objects by global identifiers
101101
List(new Flatten, // Lift all inner classes to package scope
102-
new RestoreScopes, // Repair scopes rendered invalid by moving definitions in prior phases of the group
102+
new RestoreScopes, // Repair scopes rendered invalid by moving definitions in prior phases of the group
103103
new RenameLifted, // Renames lifted classes to local numbering scheme
104104
new TransformWildcards, // Replace wildcards with default values
105105
new MoveStatics, // Move static methods to companion classes

compiler/src/dotty/tools/dotc/transform/LambdaLift.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisPhase =>
491491
val phaseName: String = "lambdaLift"
492492

493493
override def relaxedTypingInGroup = true
494+
// Because it adds free vars as additional proxy parameters
494495

495496
override def runsAfterGroupsOf: Set[Class[_ <: Phase]] = Set(classOf[Constructors], classOf[HoistSuperArgs])
496497
// Constructors has to happen before LambdaLift because the lambda lift logic

0 commit comments

Comments
 (0)