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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Takashi Kokubun
September 23, 2022
Programming
2
2.3k
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 Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
1
440
ZJIT: The Future of Ruby Performance / San Francisco Ruby Conference 2025
k0kubun
1
90
ZJIT: Building a New JIT Compiler for Ruby / REBASE 2025
k0kubun
0
89
Deoptimization: How YJIT Speeds Up Ruby by Slowing Down / RubyKaigi 2025
k0kubun
2
3.9k
YJIT Makes Rails 1.7x faster / RubyKaigi 2024
k0kubun
7
15k
Ruby JIT Hacking Guide / RubyKaigi 2023
k0kubun
2
10k
Towards Ruby 4 JIT / RubyKaigi 2022
k0kubun
3
12k
Optimizing Production Performance with MRI JIT / RubyConf 2021
k0kubun
1
530
Why Ruby's JIT was slow / RubyKaigi Takeout 2021
k0kubun
3
2k
Other Decks in Programming
See All in Programming
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
990
Codex の「自走力」を高める
yorifuji
0
1.3k
Ruby and LLM Ecosystem 2nd
koic
1
1.3k
AI Assistants for Your Angular Solutions
manfredsteyer
PRO
0
160
Geminiをパートナーに神社DXシステムを個人開発した話(いなめぐDX 開発振り返り)
fujiba
0
100
GoのDB アクセスにおける 「型安全」と「柔軟性」の両立 - Bob という選択肢
tak848
0
270
エンジニアの「手元の自動化」を加速するn8n 2026.02.27
symy2co
0
180
RailsのValidatesをSwift Macrosで再現してみた
hokuron
0
130
Pythonデータ分析コトハジメinFukuoka
kanan
0
100
Java 21/25 Virtual Threads 소개
debop
0
270
Takumiから考えるSecurity_Maturity_Model.pdf
gessy0129
1
160
Redox OS でのネームスペース管理と chroot の実現
isanethen
0
440
Featured
See All Featured
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
240
Everyday Curiosity
cassininazir
0
180
From π to Pie charts
rasagy
0
160
Thoughts on Productivity
jonyablonski
75
5.1k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
89
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
300
For a Future-Friendly Web
brad_frost
183
10k
Producing Creativity
orderedlist
PRO
348
40k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
120
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
160
Product Roadmaps are Hard
iamctodd
PRO
55
12k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.2k
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