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

optimize command-line flag checking in compiler using ConstantCallSite

Open adriaanm opened this issue 9 years ago • 7 comments

@retronym suggests we use https://community.oracle.com/blogs/forax/2011/12/17/jsr-292-goodness-almost-static-final-field to hide our instrumentation better from the JIT.

A lot of compiler settings are constant false in most compiler runs, yet they must be checked all the time. We could help the JIT using the above technique.

(See e.g., https://github.com/scala/scala/pull/5204)

adriaanm avatar Jun 02 '16 00:06 adriaanm

@retronym, smart idea!

DarkDimius avatar Jun 02 '16 06:06 DarkDimius

Aside from super hot methods, I don't hold out too much hope that we'll see big gains over and above what HotSpot would do for a conditional with a 100% biased profile. I do think we can see some gains in how fast we warm up by making sure that seldom chosen branches just delegate to a method, rather than directly contain the code.

if (usuallyTrue) { foo; bar; baz } else {rarelycalled() }

retronym avatar Jun 02 '16 07:06 retronym

Just pointing out that this will make it harder to compile scalac with non-JVM backends (duh, I can't just write "Scala.js" in those cases anymore ^^). It would be good if the way this is implemented is well isolated somewhere where it is easy to change the implementation for different platforms. (as opposed to spread this implementation detail all over the place)

sjrd avatar Jun 02 '16 08:06 sjrd

Definitely!

adriaanm avatar Jun 02 '16 22:06 adriaanm

In REPL, user would like to turn options on and off, from line to line. But you never know if a flag is cached.

Sample anti-pattern https://github.com/som-snytt/scala/blob/b462e5a97b499bc91222014e45ec2439f56b46b7/src/repl/scala/tools/nsc/interpreter/ILoop.scala#L955

som-snytt avatar Jun 03 '16 18:06 som-snytt

Yep, whatever mechanism we come up with should support embedded scenarios (as in your REPL improvement)

adriaanm avatar Jun 03 '16 20:06 adriaanm

That was of course in response to an exigent need (https://gitter.im/scala/scala?at=5751ddff9be9c5b637f03d13)

som-snytt avatar Jun 03 '16 22:06 som-snytt