Affects Version/s: None
Fix Version/s: None
When you create a collection, a lot of unnecessary work is done.
I think there's a middle ground between what we have now and macro/builtin compiler support. This reminds me an idea I had (and Miguel also mentioned to me) of early inlining. The current state of affairs is that code with foreach call like List(1,2,3) foreach println we first expand lambda to a class, we typecheck everything and generate lots of trees, then icode and only then we realize (if we are lucky) that we can inline foreach implementation, inline apply of a closure and throw away the whole class we generate for the closure. That's a huge amount of wasted work.
Quoting from The Scala Compiler Corner, about "early inlining"
- 2012-07-03: GC-savvy Closure conversion,
- 2011-11-22: Just trying to generate faster code faster under -optimise
Many of these performance problems can go away with MethodHandles and invokedynamic. Therefore this bug should be broken up into pre-JDK7 and JDK7 versions.