scala-dev icon indicating copy to clipboard operation
scala-dev copied to clipboard

hoist outer references

Open retronym opened this issue 10 years ago • 3 comments
trafficstars

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 avatar Aug 05 '15 04:08 retronym

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


thanks! keep those reports coming :-)

retronym avatar Aug 05 '15 04:08 retronym

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 avatar Aug 05 '15 04:08 retronym

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

retronym avatar Aug 05 '15 04:08 retronym