Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Ruby JIT Hacking Guide / RubyKaigi 2023
Search
Takashi Kokubun
May 13, 2023
Programming
11k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Ruby JIT Hacking Guide / RubyKaigi 2023
Ruby JIT Hacking Guide
https://rubykaigi.org/2023/
Takashi Kokubun
May 13, 2023
More Decks by Takashi Kokubun
See All by Takashi Kokubun
Lightning-Fast Method Calls with Ruby 4.1 ZJIT / RubyKaigi 2026
k0kubun
3
4k
一度始めたらやめられない開発効率向上術 / Findy あなたのdotfilesを教えて!
k0kubun
4
3.4k
ZJIT: The Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
1
590
ZJIT: The Future of Ruby Performance / San Francisco Ruby Conference 2025
k0kubun
1
170
ZJIT: Building a New JIT Compiler for Ruby / REBASE 2025
k0kubun
0
190
Deoptimization: How YJIT Speeds Up Ruby by Slowing Down / RubyKaigi 2025
k0kubun
2
5k
YJIT Makes Rails 1.7x faster / RubyKaigi 2024
k0kubun
7
16k
YJIT: Dive into Ruby's JIT compiler written in Rust / Rust.Tokyo 2022
k0kubun
2
2.4k
Towards Ruby 4 JIT / RubyKaigi 2022
k0kubun
3
12k
Other Decks in Programming
See All in Programming
自作Discord音声botをLambda MicroVMsに移行した話 / Migrating My Discord Voice Bot to Lambda MicroVMs
akihisaikeda
1
250
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
830
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
190
クラウドエージェントは、 何がそんなに便利なのか / what makes cloud agents so useful
rkaga
5
680
私なりのハーネスエンジニアリング ~独自の言語処理系の開発を通して~
seosoft
0
170
作って学ぶSpring BootのAuto Configuration / JJUG Night Seminar 2026-10-19
rshindo
0
220
高橋メソッドでCVE解説シリーズ 〜CVE-2026-112816〜
hakkadaikon
0
200
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
260
Goコンパイラを作ってGoをもっと理解する / Build a Go compiler to better understand Go
ikura_hamu
0
110
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
3
1.7k
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
260
sbt 2.0: takeoff
eed3si9n
0
190
Featured
See All Featured
Google's AI Overviews - The New Search
badams
0
1.6k
Utilizing Notion as your number one productivity tool
mfonobong
4
630
Mobile First: as difficult as doing things right
swwweet
225
10k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
730
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
Site-Speed That Sticks
csswizardry
13
1.6k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
550
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.6k
We Are The Robots
honzajavorek
0
420
Transcript
Ruby JIT Hacking Guide @k0kubun
@k0kubun
RJIT ERB Haml Slim I maintain
What's JIT?
Ruby JITs MJIT Ruby 2.6
Ruby JITs YJIT Ruby 3.1 MJIT Ruby 2.6
Ruby JITs YJIT Ruby 3.1 MJIT Ruby 2.6 RJIT Ruby
3.3
Railsbench Speedup relative to 2.5 No JIT (s/s) 0 0.5
1 1.5 2 Ruby 2.5 Ruby 2.6 Ruby 2.7 Ruby 3.0 Ruby 3.1 Ruby 3.2 Ruby 3.3 1.93 1.85 1.54 1.59 1.2 1.25 1.08 1.05 1.07 1.26 1.24 1.12 1.09 1.05 1.07 1 No JIT MJIT / RJIT YJIT
Ruby 3.2 YJIT
Ruby 3.3 YJIT
Using YJIT • Install Rust and then build Ruby •
Use --yjit or export RUBY_YJIT_ENABLE=1
Ruby JIT Hacking Guide
Ruby Hacking Guide
Ruby JIT Hacking Guide JIT JIT
How Ruby JIT works Ruby
How Ruby JIT works 1 + 2 Ruby Abstract
Syntax Tree
How Ruby JIT works 1 + 2 putobject 1 putobject
2 opt_plus leave Ruby Abstract Syntax Tree Instruction Sequence (Bytecode)
How Ruby JIT works 1 + 2 putobject 1 putobject
2 opt_plus leave Ruby Abstract Syntax Tree Instruction Sequence (Bytecode) Machine Code
x86_64 assembly
• Read asm comments •--yjit-dump-disasm •--rjit-dump-disasm x86_64 assembly
• mov: assignment instruction • esi: register for stack[0] x86_64
assembly stack[0] = 3
x86_64 assembly • mov: assignment instruction • edi: register for
stack[1] stack[0] = 3 stack[1] = 5
x86_64 assembly • add,sub: arithmetic instruction • rax: temporary register
stack[0] = 3 stack[1] = 5 temp = stack[0] temp -= 1 temp += stack[1]
x86_64 assembly • jo: jump if over fl ow •
rsi: register for stack[0] stack[0] = 3 stack[1] = 5 temp = stack[0] temp -= 1 temp += stack[1] jump if overflow stack[0] = temp
x86_64 encoding
x86_64 encoding opv86: https://hikalium.github.io/opv86/
x86_64 encoding opv86: https://hikalium.github.io/opv86/
Calling a custom JIT Ruby 3.2 Ruby 3.3+ 1. Run
Ruby with --mjit=pause --rjit=pause 2. Override RubyVM::MJIT.compile RubyVM::RJIT#compile 3. Call RubyVM::MJIT.resume RubyVM::RJIT.resume
Building JIT is fun
k0kubun/ruby-jit-challenge Ruby JIT Challenge
Ruby JIT Challenge Hashtag: #ruby-jit-challenge Speedup relative to No JIT
(s/s) 0 3 6 9 12 No JIT RJIT YJIT Ruby JIT 11.08 6.31 3.75 1 Fibonatti benchmark
Optimizing Ruby JIT
Side exits side exit
Method rede fi nition Rede fi nition Hook Invalidate
Method rede fi nition Rede fi nition Hook Invalidate side
exit
Constant rede fi nition
Register allocation: Stack 0: rsi 1: rdi 4: r10 2:
r8 3: r9 VM stack
Register allocation: Stack 0: rsi 1: rdi 4: r10 2:
r8 3: r9 VM stack
Register allocation: Local variables • Spill registers on C function
calls • Binding • debug_inspector API
Polymorphic method cache
Splitting
Method inlining
Conclusion • Enjoy custom JIT development • Let's make YJIT
the best Ruby JIT