top | item 38270667

(no title)

xerxes901 | 2 years ago

I don't work on YJIT but I _think_ i know the (or maybe an) answer to this. The code for a JIT'd ruby method isn't contiguous in one location in memory. When a ruby method is first compiled, a straightline path through the method is emitted , and branches are emitted as stub code. When the stub is hit, the incremental compilation of that branch then happens. I believe this is called "lazy basic block versioning".

When the stub is hit the code that gets generated is somewhere _else_ in executable memory, not contiguous with the original bit of the method. Because these "lazy basic blocks" are actually quite small, the bookkeeping involved in "where is the code for this ruby method" would actually be an appreciable fraction of the code size itself. Plus you then have to do more bookkeeping to make sure the method you want to GC isn't referred to by the generated code in another method.

Since low memory usage is an important YJIT goal, I guess this tradeoff isn't worth it.

Maybe someone who knows this better will come along and correct me :)

discuss

order

JohnBooty|2 years ago

Seems you hit the nail on the head. Thanks for the informative answer!