$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
YJIT: Dive into Ruby's JIT compiler written in ...
Search
Takashi Kokubun
September 23, 2022
Programming
2
2.2k
YJIT: Dive into Ruby's JIT compiler written in Rust / Rust.Tokyo 2022
Rust.Tokyo 2022
Takashi Kokubun
September 23, 2022
Tweet
Share
More Decks by Takashi Kokubun
See All by Takashi Kokubun
ZJIT: The Future of Ruby Performance / San Francisco Ruby Conference 2025
k0kubun
1
43
ZJIT: Building a New JIT Compiler for Ruby / REBASE 2025
k0kubun
0
34
Deoptimization: How YJIT Speeds Up Ruby by Slowing Down / RubyKaigi 2025
k0kubun
2
3.5k
YJIT Makes Rails 1.7x faster / RubyKaigi 2024
k0kubun
7
14k
Ruby JIT Hacking Guide / RubyKaigi 2023
k0kubun
2
10k
Towards Ruby 4 JIT / RubyKaigi 2022
k0kubun
3
11k
Optimizing Production Performance with MRI JIT / RubyConf 2021
k0kubun
1
500
Why Ruby's JIT was slow / RubyKaigi Takeout 2021
k0kubun
3
2k
数時間かかる週一リリースを毎日何度も爆速でできるようにするまで / CI/CD Conference 2021
k0kubun
21
14k
Other Decks in Programming
See All in Programming
connect-python: convenient protobuf RPC for Python
anuraaga
0
370
無秩序からの脱却 / Emergence from chaos
nrslib
2
12k
「コードは上から下へ読むのが一番」と思った時に、思い出してほしい話
panda728
PRO
37
23k
エディターってAIで操作できるんだぜ
kis9a
0
690
Full-Cycle Reactivity in Angular: SignalStore mit Signal Forms und Resources
manfredsteyer
PRO
0
120
CSC509 Lecture 14
javiergs
PRO
0
220
Full-Cycle Reactivity in Angular: SignalStore mit Signal Forms und Resources
manfredsteyer
PRO
0
200
Why Kotlin? 電子カルテを Kotlin で開発する理由 / Why Kotlin? at Henry
agatan
2
6.8k
dotfiles 式年遷宮 令和最新版
masawada
1
700
大体よく分かるscala.collection.immutable.HashMap ~ Compressed Hash-Array Mapped Prefix-tree (CHAMP) ~
matsu_chara
1
210
sbt 2
xuwei_k
0
230
AWS CDKの推しポイントN選
akihisaikeda
1
240
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.5k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
380
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.5k
A designer walks into a library…
pauljervisheath
210
24k
Building Applications with DynamoDB
mza
96
6.8k
Typedesign – Prime Four
hannesfritz
42
2.9k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.3k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
The Pragmatic Product Professional
lauravandoore
37
7.1k
YesSQL, Process and Tooling at Scale
rocio
174
15k
The Language of Interfaces
destraynor
162
25k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
1
89
Transcript
YJIT: Dive into Ruby's JIT compiler written in Rust @k0kubun
/ Rust.Tokyo 2022
Me • @k0kubun • Shopify ◦ YJIT team • Ruby
committer ◦ MJIT maintainer
What’s YJIT?
None
None
None
None
How does YJIT work?
How YJIT works Ruby code
How YJIT works 1 + 2 Parse Ruby code Abstract
Syntax Tree
How YJIT works 1 + 2 Parse Ruby code Abstract
Syntax Tree putobject 1 putobject 2 opt_plus leave Compile Bytecode
How YJIT works 1 + 2 Parse Ruby code Abstract
Syntax Tree putobject 1 putobject 2 opt_plus leave Compile JIT Bytecode Machine code
How YJIT works putobject 1 putobject 2 opt_plus leave JIT
? Machine code Bytecode
How YJIT works: Ruby 3.1 putobject 1 putobject 2 opt_plus
leave x86_64 Codegen Machine code Bytecode
How YJIT works: Ruby 3.2 putobject 1 putobject 2 opt_plus
leave Machine code Bytecode
How YJIT works: Ruby 3.2 putobject 1 putobject 2 opt_plus
leave Machine code Bytecode
Lazy Basic Block Versioning
Lazily compile basic blocks
getlocal a getlocal b opt_plus setlocal c getlocal c putobject
1 opt_gt branchunless getlocal a leave getlocal b leave Lazily compile basic blocks
Lazily compile basic blocks
getlocal a getlocal b opt_plus setlocal c getlocal c putobject
1 opt_gt branchunless Branch stub Branch stub Lazily compile basic blocks
getlocal a getlocal b opt_plus setlocal c getlocal c putobject
1 opt_gt branchunless getlocal a leave Branch stub Lazily compile basic blocks
getlocal a getlocal b opt_plus setlocal c getlocal c putobject
1 opt_gt branchunless getlocal a leave Branch stub Lazily compile basic blocks
getlocal a getlocal b opt_plus setlocal c getlocal c putobject
1 opt_gt branchunless getlocal a leave getlocal b leave Lazily compile basic blocks
Why lazy compilation? 1. Better code locality a. Only compile
used paths b. Related code is put together
Why lazy compilation? 1. Better code locality a. Only compile
used paths b. Related code is put together 2. More type information
Type Profiling
Type Profiling getlocal a getlocal b opt_plus
Type Profiling getlocal a getlocal b opt_plus
Type Profiling getlocal a getlocal b jmp regenerate
Type Profiling getlocal a getlocal b jmp regenerate
Type Profiling getlocal a getlocal b jmp regenerate a: 1
b: 2
Type Profiling getlocal a getlocal b opt_plus (int) setlocal c
getlocal c putobject 1 opt_gt branchunless
Passes • CodeGen -> Split -> Alloc Regs
Passes • CodeGen -> Split -> Alloc Regs
IR
IR Split
IR Split Alloc Regs
Rust Challenges
Clang and Bindgen Clang dependency or Per-architecture codegen?
Mutable Borrow
Next steps • Code GC • Register allocation • Method
inlining
Conclusion • We reviewed the architecture of YJIT • Rust
has been useful for transforming IR