From 575c2da03241d04678cd53273dc46d67d3cbd288 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Mon, 29 Jan 2018 21:27:15 +0100 Subject: [PATCH] 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 --- .../src/dotty/tools/dotc/transform/Splitter.scala | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/Splitter.scala b/compiler/src/dotty/tools/dotc/transform/Splitter.scala index 65a8143cd267..88f5f986632a 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splitter.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splitter.scala @@ -23,11 +23,22 @@ class Splitter extends MiniPhase { recur(tree.fun) } + private def needsDistribution(fun: Tree) = fun match { + case _: Block | _: If => true + case _ => false + } + override def transformTypeApply(tree: TypeApply)(implicit ctx: Context) = - distribute(tree, typeApply) + if (needsDistribution(tree.fun)) + distribute(tree, typeApply) + else + tree override def transformApply(tree: Apply)(implicit ctx: Context) = - distribute(tree, apply) + if (needsDistribution(tree.fun)) + distribute(tree, apply) + else + tree private val typeApply = (fn: Tree, args: List[Tree]) => (ctx: Context) => TypeApply(fn, args)(ctx) private val apply = (fn: Tree, args: List[Tree]) => (ctx: Context) => Apply(fn, args)(ctx)