summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/UnCurry.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-08-15 16:58:02 -0700
committerPaul Phillips <paulp@improving.org>2012-08-17 06:24:42 -0700
commit1b3054c077cbc65ce20d6ba22173015bb772a353 (patch)
tree769b784cc0b010bb4feebe1d78d00684b31974e0 /src/compiler/scala/tools/nsc/transform/UnCurry.scala
parent1375fd70d2a57dd5a4096ae6ad883c0bae690cd5 (diff)
downloadscala-1b3054c077cbc65ce20d6ba22173015bb772a353.tar.gz
scala-1b3054c077cbc65ce20d6ba22173015bb772a353.tar.bz2
scala-1b3054c077cbc65ce20d6ba22173015bb772a353.zip
Hunting down eliminable :: allocations.
With this commit, the number of :: allocations logged in total after individually compiling each scala file in src/compiler drops from 190,766,642 to 170,679,925. Twenty million fewer colon-colons in the world, it's a start. For some heavily used lists like List(List()) I made vals so we can reuse the same one every time, e.g. val ListOfNil = List(Nil) The modifications in this patch were informed by logging call frequency to List.apply and examining the heaviest users. >> Origins tag 'listApply' logged 3041128 calls from 318 distinguished sources. 1497759 scala.reflect.internal.Definitions$ValueClassDefinitions$class.ScalaValueClasses(Definitions.scala:149) 173737 scala.reflect.internal.Symbols$Symbol.alternatives(Symbols.scala:1525) 148642 scala.tools.nsc.typechecker.SuperAccessors$SuperAccTransformer.transform(SuperAccessors.scala:306) 141676 scala.tools.nsc.transform.SpecializeTypes$$anonfun$scala$tools$nsc$transform$SpecializeTypes$$specializedOn$3.apply(SpecializeTypes.scala:114) 69049 scala.tools.nsc.transform.LazyVals$LazyValues$$anonfun$1.apply(LazyVals.scala:79) 62854 scala.tools.nsc.transform.SpecializeTypes.specializedTypeVars(SpecializeTypes.scala:427) 54781 scala.tools.nsc.typechecker.SuperAccessors$SuperAccTransformer.transform(SuperAccessors.scala:293) 54486 scala.reflect.internal.Symbols$Symbol.newSyntheticValueParams(Symbols.scala:334) 53843 scala.tools.nsc.backend.icode.Opcodes$opcodes$CZJUMP.<init>(Opcodes.scala:562) ... etc.
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/UnCurry.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
index e98bf519fe..aae9625e2d 100644
--- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala
+++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
@@ -35,8 +35,8 @@ import language.postfixOps
* - convert non-local returns to throws with enclosing try statements.
* - convert try-catch expressions in contexts where there might be values on the stack to
* a local method and a call to it (since an exception empties the evaluation stack):
- *
- * meth(x_1,..., try { x_i } catch { ..}, .. x_b0) ==>
+ *
+ * meth(x_1,..., try { x_i } catch { ..}, .. x_b0) ==>
* {
* def liftedTry$1 = try { x_i } catch { .. }
* meth(x_1, .., liftedTry$1(), .. )
@@ -271,7 +271,7 @@ abstract class UnCurry extends InfoTransform
localTyper.typedPos(fun.pos) {
Block(
- List(ClassDef(anonClass, NoMods, List(List()), List(List()), List(applyMethodDef), fun.pos)),
+ List(ClassDef(anonClass, NoMods, ListOfNil, ListOfNil, List(applyMethodDef), fun.pos)),
Typed(New(anonClass.tpe), TypeTree(fun.tpe)))
}
@@ -396,7 +396,7 @@ abstract class UnCurry extends InfoTransform
localTyper.typedPos(fun.pos) {
Block(
- List(ClassDef(anonClass, NoMods, List(List()), List(List()), List(applyOrElseMethodDef, isDefinedAtMethodDef), fun.pos)),
+ List(ClassDef(anonClass, NoMods, ListOfNil, ListOfNil, List(applyOrElseMethodDef, isDefinedAtMethodDef), fun.pos)),
Typed(New(anonClass.tpe), TypeTree(fun.tpe)))
}
}
@@ -558,7 +558,7 @@ abstract class UnCurry extends InfoTransform
sym.setInfo(MethodType(List(), tree.tpe))
tree.changeOwner(currentOwner -> sym)
localTyper.typedPos(tree.pos)(Block(
- List(DefDef(sym, List(Nil), tree)),
+ List(DefDef(sym, ListOfNil, tree)),
Apply(Ident(sym), Nil)
))
}
@@ -641,7 +641,7 @@ abstract class UnCurry extends InfoTransform
case ret @ Return(_) if (isNonLocalReturn(ret)) =>
withNeedLift(true) { super.transform(ret) }
- case Try(_, Nil, _) =>
+ case Try(_, Nil, _) =>
// try-finally does not need lifting: lifting is needed only for try-catch
// expressions that are evaluated in a context where the stack might not be empty.
// `finally` does not attempt to continue evaluation after an exception, so the fact
@@ -711,8 +711,12 @@ abstract class UnCurry extends InfoTransform
}
case dd @ DefDef(_, _, _, vparamss0, _, rhs0) =>
+ val vparamss1 = vparamss0 match {
+ case _ :: Nil => vparamss0
+ case _ => vparamss0.flatten :: Nil
+ }
val flatdd = copyDefDef(dd)(
- vparamss = List(vparamss0.flatten),
+ vparamss = vparamss1,
rhs = nonLocalReturnKeys get dd.symbol match {
case Some(k) => atPos(rhs0.pos)(nonLocalReturnTry(rhs0, k, dd.symbol))
case None => rhs0