Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
1
2.1k
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
Deoptimization: How YJIT Speeds Up Ruby by Slowing Down / RubyKaigi 2025
k0kubun
2
2.7k
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
460
Why Ruby's JIT was slow / RubyKaigi Takeout 2021
k0kubun
3
1.9k
数時間かかる週一リリースを毎日何度も爆速でできるようにするまで / CI/CD Conference 2021
k0kubun
21
14k
Ruby 3 JIT's roadmap / RubyConf China 2020
k0kubun
0
820
Ruby 3.0 JIT on Rails
k0kubun
9
9.3k
Other Decks in Programming
See All in Programming
推論された型の移植性エラーTS2742に挑む
teamlab
PRO
0
150
人には人それぞれのサービス層がある
shimabox
3
480
Language Server と喋ろう – TSKaigi 2025
pizzacat83
3
750
Interface vs Types ~型推論が過多推論~
hirokiomote
1
240
primeNumberでのRBS導入の現在 && RBS::Traceでinline RBSを拡充してみた
mnmandahalf
0
260
TVer iOSチームの共通認識の作り方 - Findy Job LT iOSアプリ開発の裏側 開発組織が向き合う課題とこれから
techtver
PRO
0
720
Perlで痩せる
yuukis
1
660
Babylon.js 8.0のアプデ情報を 軽率にキャッチアップ / catch-up-babylonjs-8
drumath2237
0
110
衛星の軌道をWeb地図上に表示する
sankichi92
0
250
マテリアルって何者?RealityKitで扱うマテリアル入門
nao_randd
0
140
技術懸念に立ち向かい 法改正を穏便に乗り切った話
pop_cashew
0
900
當開發遇上包裝:AI 如何讓產品從想法變成商品
clonn
0
2.6k
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
VelocityConf: Rendering Performance Case Studies
addyosmani
329
24k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
123
52k
Typedesign – Prime Four
hannesfritz
41
2.6k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.5k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Designing for humans not robots
tammielis
253
25k
GraphQLとの向き合い方2022年版
quramy
46
14k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
48
5.4k
Designing Experiences People Love
moore
142
24k
Music & Morning Musume
bryan
47
6.6k
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