Skip to content

Commit 575c2da

Browse files
committed
Splitter: Avoid unnecessary allocations (20% fewer Apply nodes)
When compiling dotty-compiler, this reduces the total number of allocated Apply nodes from 649879 to 506536, and the total number of allocated TypeApply nodes from 111097 to 95094
1 parent 0cf569f commit 575c2da

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,22 @@ class Splitter extends MiniPhase {
2323
recur(tree.fun)
2424
}
2525

26+
private def needsDistribution(fun: Tree) = fun match {
27+
case _: Block | _: If => true
28+
case _ => false
29+
}
30+
2631
override def transformTypeApply(tree: TypeApply)(implicit ctx: Context) =
27-
distribute(tree, typeApply)
32+
if (needsDistribution(tree.fun))
33+
distribute(tree, typeApply)
34+
else
35+
tree
2836

2937
override def transformApply(tree: Apply)(implicit ctx: Context) =
30-
distribute(tree, apply)
38+
if (needsDistribution(tree.fun))
39+
distribute(tree, apply)
40+
else
41+
tree
3142

3243
private val typeApply = (fn: Tree, args: List[Tree]) => (ctx: Context) => TypeApply(fn, args)(ctx)
3344
private val apply = (fn: Tree, args: List[Tree]) => (ctx: Context) => Apply(fn, args)(ctx)

0 commit comments

Comments
 (0)