Eliminating allocations. #1823

Merged
merged 14 commits into from Dec 31, 2012

Projects

None yet

4 participants

@paulp
At this commit the statistics when compiling src/library
are as follows. These counts are precise, collected by a
modified Function1 which counts every instantiation of every
implementing class. The net result is 27 million fewer
allocations, over a 20% drop.

  // master (5b5635ee9d), total and top five by count:
  Total Function1 allocations: 128,805,865

  scala.collection.immutable.$colon$colon 26781958
  scala.collection.mutable.ListBuffer 15365174
  scala.collection.TraversableLike$$anonfun$map$1 9127787
  scala.collection.generic.Growable$$anonfun$$plus$plus$eq$1 4636154
  scala.collection.mutable.StringBuilder 3531211

  // After these commits, total and top five by count:
  Total Function1 allocations: 101,865,721

  scala.collection.immutable.$colon$colon 26993704
  scala.collection.mutable.ListBuffer 15319656
  scala.collection.TraversableLike$$anonfun$map$1 7585019
  scala.reflect.internal.Types$MethodType$$anonfun$paramTypes$1 2447307
  scala.reflect.internal.Types$SubstSymMap 2436088
paulp added some commits Nov 29, 2012
@paulp paulp Eliminate allocations in ListBuffer.
++= on a linear sequence can be accomplished without
closure allocation.
3f9943b
@paulp paulp Eliminate allocations in ClassfileParser. c53359e
@paulp paulp Eliminating more allocations in the collections. 3059e3a
@paulp paulp Eliminating allocations in Codec. 78269a6
@paulp paulp Eliminating allocations in typeDepth. d3099c0
@paulp paulp Eliminate allocations in Growable. 1697132
@paulp paulp Eliminate allocations in TypeMap. bf253b8
@paulp paulp Eliminate allocations in CPSAnnotationChecker. 2e3e43b
@paulp paulp Eliminate allocations in BaseTypeSeqs. 9a6320b
@paulp paulp Eliminate allocations in uncurry and the backend. cdf6feb
@paulp paulp Eliminate allocations in Trees. 113405b
@paulp paulp Eliminate allocations in Specialize. 57c40c5
@paulp paulp Eliminate allocations in Trees and Symbols. eb491d2
@paulp paulp Eliminate allocations in Types.
At this commit the statistics when compiling src/library
are as follows. These counts are precise, collected by a
modified Function1 which counts every instantiation of every
implementing class. The net result is 27 million fewer
allocations, over a 20% drop.

  // master (5b5635ee9d), total and top five by count:
  Total Function1 allocations: 128,805,865

  scala.collection.immutable.$colon$colon 26781958
  scala.collection.mutable.ListBuffer 15365174
  scala.collection.TraversableLike$$anonfun$map$1 9127787
  scala.collection.generic.Growable$$anonfun$$plus$plus$eq$1 4636154
  scala.collection.mutable.StringBuilder 3531211

  // After these commits, total and top five by count:
  Total Function1 allocations: 101,865,721

  scala.collection.immutable.$colon$colon 26993704
  scala.collection.mutable.ListBuffer 15319656
  scala.collection.TraversableLike$$anonfun$map$1 7585019
  scala.reflect.internal.Types$MethodType$$anonfun$paramTypes$1 2447307
  scala.reflect.internal.Types$SubstSymMap 2436088
6a288b6
@soc
The Scala Programming Language member

This looks very impressive to me, but is it sure that the compiler won't be able to do this optimization automatically in the foreseeable future?

@paulp

Would it matter if it did? It's not like these patches leave the wreckage of elegance in their wake.

But no, the compiler won't be performing these optimization(s) (there are at least three or four different approaches in here) anytime soon.

@paulp

Perhaps @JamesIry would like to review this one.

@JamesIry

LGTM, but also makes me sad.

@paulp

We'll turn your sad panda face upside down eventually.

@paulp paulp merged commit 6665722 into scala:master Dec 31, 2012
@paulp paulp deleted the unknown repository branch Dec 31, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment