This page is no longer maintained — Please continue to the home page at www.scala-lang.org

optimization of comprehensions

2 replies
Miguel Garcia
Joined: 2009-06-10,
User offline. Last seen 42 years 45 weeks ago.

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

Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: optimization of comprehensions


On Wed, Jul 29, 2009 at 12:15 PM, Miguel Garcia <miguel.garcia@tuhh.de> 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?

Do you have a performance problem with for comprehensions?
 


Miguel
http://www.sts.tu-harburg.de/people/mi.garcia





--
Viktor Klang

Rogue Scala-head

Blog: klangism.blogspot.com
Twttr: viktorklang
Iulian Dragos 2
Joined: 2009-02-10,
User offline. Last seen 42 years 45 weeks ago.
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
>
>
>

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland