reactorlabs / rir

GNU General Public License v2.0
62 stars 18 forks source link

Effect of OSRing callee from a caller #1252

Open fikovnik opened 12 months ago

fikovnik commented 12 months ago

We were talking with Sebastian about this one. I'm not sure I understand the motivation, but currently it could trigger unnecessary compilation thanks to time-based recompilation heuristics. The effect of removing ti seems to be fairly marginal, but that is of course just on the benchmark:

https://rir-benchmarks.prl.fit.cvut.cz/diff?job_ids%5B%5D=5240762468&job_ids%5B%5D=4452171149&kind=diff&selection=main&warmup=5

fikovnik commented 11 months ago

I think I understand the motivation now. It is best explained on the following code (taken form the benchmark suite):

execute <- function(n) {
  x <- 0
  f <- function() {
    while (x < n) {
      x <<- x + 1
    }
  }
  f()
}

execute(20000000)
execute(20000000)
execute(20000000)
execute(20000000)
execute(20000000)

It should first trigger OSR form within the loop. Upon the next invocation, f will be recompiled and that recompilation will trigger the compilation of execute. Without it, execute will never compile as it is only invoked a few times. However, the callee-caller OSR is guarded by the callee bytecode size - currently hardcoded to 20. The body size of f is 159.

It would probably be better to increase the threshold. However, by doing so all sorts of things start to fail. It seems that now we compile form places we did not compile before. I nee do to investigate.