scala / scala-dev

Scala 2 team issues. Not for user-facing bugs or directly actionable user-facing improvements. For build/test/infra and for longer-term planning and idea tracking. Our bug tracker is at https://github.com/scala/bug/issues
Apache License 2.0
130 stars 14 forks source link

hoist outer references #24

Open retronym opened 9 years ago

retronym commented 9 years ago

In code like:

class Outer {
  var a, b = 0
  class Inner {
    def test = {
       (a, b)
     }
  }
}

Rather than emitting:

  def test = { ($outer.a, $outer.b) }

We could emit:

   def test = { val $outer$1 = $outer; ($outer$1.a, $outer$1.b) }

I believe that in Miguel's prototype of the new optimizer he did something similar for module references.

Before trying this, we should of course see if the JVM handles this itself. But I did a potential inefficiency in outer access in hot methods like Symbol#rawInfo when analysing Java Flight Recorder profiles. (Caveat: today is my first day playing with JFR so don't take those numbers to heart!)

image

retronym commented 9 years ago

Comment by lrytz Tuesday Mar 31, 2015 at 07:03 GMT


thanks! keep those reports coming :-)

retronym commented 9 years ago

Comment by retronym Tuesday Mar 31, 2015 at 07:08 GMT


I'm making a bigger list of ideas https://gist.github.com/retronym/86ec6ad9ccd2c22f6148

As I find ideas for the optimizer, I'll keep noting them here.

retronym commented 9 years ago

Comment by lrytz Wednesday Apr 01, 2015 at 06:28 GMT


note: should probably null out the local when it's no longer in use, https://github.com/scala-opt/scala/issues/6