BYOJ: Build your own JIT with Ruby
summary
Explains building a JIT in Ruby using the Rjit gem and an assembler or Fiddle to emit machine code, handling YARV instructions like put_nil, leave, putobject and opt_plus, mapping stack slots to registers (examples use R8/R9), updating the control frame pointer and execution context and moving the return into the RX register. Demonstrates a working compiler class with compile hooks, reports up to about 2x speedups from RubyBench versus no JIT, and shows a surprising 420 monkeypatch that proves you can alter semantics at the machine level.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 1:07What is a JIT
- 2:13Ruby’s JIT evolution
- 3:19Stack vs register machines
- 6:14Ruby VM instructions
- 10:29Custom JIT with RJIT
- 12:38Compiling put nil
- 16:15JIT simple addition
- 18:03JIT performance benchmarks
- 18:46RJIT monkey patching
- 20:00Closing
related talks
36mSome Assembly Required
30mYJIT - Building a new JIT Compiler inside CRuby
17mYJIT: A Basic Block Versioning JIT Compiler
37mKeynote: YJIT's Three Languages: the Fun of Code that Writes Code
20mEvaluating YJIT’s Performance in a Production Context: A Pragmatic Approach
40mThe secret power of Ruby 2.6: JIT
33mRuby the Hard Way: Writing Bytecode to Optimize Plain Ruby
32mExperiments in sharing Java VM technology with CRuby
