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
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: Building a New JIT Compiler for Ruby / REBASE 2025
k0kubun
0
13
Deoptimization: How YJIT Speeds Up Ruby by Slowing Down / RubyKaigi 2025
k0kubun
2
3.4k
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
480
Why Ruby's JIT was slow / RubyKaigi Takeout 2021
k0kubun
3
2k
数時間かかる週一リリースを毎日何度も爆速でできるようにするまで / CI/CD Conference 2021
k0kubun
21
14k
Ruby 3 JIT's roadmap / RubyConf China 2020
k0kubun
0
840
Other Decks in Programming
See All in Programming
Go言語の特性を活かした公式MCP SDKの設計
hond0413
1
240
品質ワークショップをやってみた
nealle
0
550
Le côté obscur des IA génératives
pascallemerrer
0
150
スマホから Youtube Shortsを見られないようにする
lemolatoon
27
33k
XP, Testing and ninja testing ZOZ5
m_seki
3
730
20251016_Rails News ~Rails 8.1の足音を聴く~
morimorihoge
2
510
(Extension DC 2025) Actor境界を越える技術
teamhimeh
1
260
CSC509 Lecture 06
javiergs
PRO
0
260
CSC509 Lecture 05
javiergs
PRO
0
300
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
280
Writing Better Go: Lessons from 10 Code Reviews
konradreiche
0
2k
Devoxx BE 2025 Loom lab
josepaumard
0
100
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Designing for humans not robots
tammielis
254
26k
Raft: Consensus for Rubyists
vanstee
140
7.1k
Designing Experiences People Love
moore
142
24k
Gamification - CAS2011
davidbonilla
81
5.5k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
Agile that works and the tools we love
rasmusluckow
331
21k
Building a Modern Day E-commerce SEO Strategy
aleyda
44
7.8k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
For a Future-Friendly Web
brad_frost
180
10k
RailsConf 2023
tenderlove
30
1.3k
The Power of CSS Pseudo Elements
geoffreycrofte
79
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