- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
optimization of comprehensions
Wed, 2009-07-29, 11:16
Hi,
Sometime ago I was trying to see how comprehensions were optimized, with one
experiment involving:
val res2 = Set(1, 2, 3) map (x => x)
The result being that after typer, the identity function was still there:
res2: scala.collection.immutable.Set =
scala.this.Predef.Set().apply(
new scala.runtime.BoxedIntArray( Array[Int]{1,2,3}) )
.map( {(new QueryDesugar$$anonfun$2(): Function1)} )
I guess optimization away subexpressions has to do with detecting purity,
and that in turn with effect systems. Other than that, are there any ideas
on the pipeline regarding comprehensions optimization?
Wed, 2009-07-29, 13:17
#2
Re: optimization of comprehensions
Hi Miguel,
Optimizations are done much later in the compiler. You can check the
generated bytecode to see what gets removed, in general closures and
higher order functions are preferred targets when optimizing.
iulian
Miguel Garcia wrote:
> Hi,
>
> Sometime ago I was trying to see how comprehensions were optimized, with one
> experiment involving:
>
> val res2 = Set(1, 2, 3) map (x => x)
>
> The result being that after typer, the identity function was still there:
>
> res2: scala.collection.immutable.Set =
> scala.this.Predef.Set().apply(
> new scala.runtime.BoxedIntArray( Array[Int]{1,2,3}) )
> .map( {(new QueryDesugar$$anonfun$2(): Function1)} )
>
> I guess optimization away subexpressions has to do with detecting purity,
> and that in turn with effect systems. Other than that, are there any ideas
> on the pipeline regarding comprehensions optimization?
>
>
> Miguel
> http://www.sts.tu-harburg.de/people/mi.garcia
>
>
>
On Wed, Jul 29, 2009 at 12:15 PM, Miguel Garcia <miguel.garcia@tuhh.de> wrote:
Do you have a performance problem with for comprehensions?
--
Viktor Klang
Rogue Scala-head
Blog: klangism.blogspot.com
Twttr: viktorklang