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
Ruby 2.6 JIT / RubyConf 2018
Search
Takashi Kokubun
November 15, 2018
Programming
15
13k
Ruby 2.6 JIT / RubyConf 2018
RubyConf 2018 Los Angeles
Takashi Kokubun
November 15, 2018
Tweet
Share
More Decks by Takashi Kokubun
See All by Takashi Kokubun
YJIT Makes Rails 1.7x faster / RubyKaigi 2024
k0kubun
7
12k
Ruby JIT Hacking Guide / RubyKaigi 2023
k0kubun
2
9.4k
YJIT: Dive into Ruby's JIT compiler written in Rust / Rust.Tokyo 2022
k0kubun
1
2k
Towards Ruby 4 JIT / RubyKaigi 2022
k0kubun
3
11k
Optimizing Production Performance with MRI JIT / RubyConf 2021
k0kubun
1
410
Why Ruby's JIT was slow / RubyKaigi Takeout 2021
k0kubun
3
1.8k
数時間かかる週一リリースを毎日何度も爆速でできるようにするまで / CI/CD Conference 2021
k0kubun
21
14k
Ruby 3 JIT's roadmap / RubyConf China 2020
k0kubun
0
760
Ruby 3.0 JIT on Rails
k0kubun
9
9.1k
Other Decks in Programming
See All in Programming
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
130
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.2k
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
CSC509 Lecture 11
javiergs
PRO
0
180
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Realtime API 入門
riofujimon
0
150
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Happy Clients
brianwarren
98
6.7k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
The Language of Interfaces
destraynor
154
24k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Facilitating Awesome Meetings
lara
50
6.1k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Transcript
Takashi Kokubun @k0kubun Ruby 2.6 JIT
@k0kubun Takashi Kokubun / Arm Ruby Committer for JIT, ERB
None
None
None
None
Ruby 2.6
None
What's "JIT"?
JIT: Just In Time Compiler
None
History of Ruby implementation
def plus(a, b) a + b end + a b
Parse Ruby 1.8 Traverse
def plus(a, b) a + b end + a b
Compile Ruby 1.9~2.5 Interpret getlocal :a getlocal :b send :+
def plus(a, b) a + b end + a b
JIT Ruby 2.6 (New!) Execute getlocal :a getlocal :b send :+ mov %rdi,%rdx mov %rsi,%rax add %rdx,%rax
How can we use it?
or ruby --jit ... RUBYOPT="--jit" rails s ...
Let's benchmark Ruby 2.6 JIT
None
https://gist.github.com/k0kubun/887b9567afa86b326556389ef00e4200
https://gist.github.com/k0kubun/887b9567afa86b326556389ef00e4200 Ruby 2.0: 34.3 Ruby 2.6: 86.7 2.53x faster
https://gist.github.com/k0kubun/887b9567afa86b326556389ef00e4200 Ruby 2.5: 48.3 Ruby 2.6: 86.7 1.80x faster
Achieved Ruby 3x2.5 !!!
How about other benchmarks?
None
None
JIT makes things slower?
Today's topic JIT performance characteristics
When does Ruby become slow on JIT?
1. When there are many JIT-ed methods
--jit-max-cache (default: 1000)
JIT by C compiler & dynamic loading
unused space code readonly data 1 method Heap
unused space code readonly data 1 method Heap 2MB (big)
about 4KB ?KB
unused space code readonly data unused space code readonly data
unused space code readonly data 3 methods Heap
unused space code readonly data unused space code readonly data
unused space code readonly data L2, ... cache L1 cache Heap
unused space code readonly data unused space code readonly data
unused space code readonly data L2, ... cache L1 cache Heap
unused space Heap code readonly data unused space code readonly
data unused space code readonly data L2, ... cache L1 cache
2. When there are still methods to be JIT-ed
"JIT compaction"
unused space code readonly data unused space code readonly data
unused space code readonly data When it reaches --jit-max-cache, it fires "JIT compaction"
unused space code readonly data unused space code readonly data
unused space code readonly data unused space code code code readonly data readonly data readonly data
unused space code readonly data unused space code readonly data
unused space code readonly data unused space code code code readonly data readonly data readonly data L2, ... cache
CPU/memory resources for C compiler
Locks on GC, waitpid, ...
3. When TracePoint is enabled (to be fixed after Ruby
2.6)
What's TracePoint? When is it enabled? • gem 'web-console' on
your Rails application • byebug or binding.pry (with pry-byebug) • Measuring coverage
Summary: When JIT makes Ruby slow Optcarrot Rails 1. When
there are many JIT-ed methods ✓ 2. When there are still methods to be JIT-ed (Is it a short benchmark?) ✓ 3. When TracePoint is enabled
What is made faster by JIT?
1. Almost all methods
def plus(a, b) a + b end Virtual Machine getlocal
:a getlocal :b send :+ Program Counter Stack Pointer Computer Registers Instruction Pointer
def plus(a, b) a + b end Virtual Machine getlocal
:a getlocal :b send :+ Program Counter Stack Pointer Computer JIT Instruction Pointer Registers mov %rdi,%rdx mov %rsi,%rax add %rdx,%rax
2. Basic operators on core classes
VM-optimized methods Integer, Float +, -, *, /, % Array
+, <<, [], []=, empty?, size, length, min, max Hash [], []=, empty?, size, length String +, <<, =~, empty?, size, length, succ common !, !=, ==, <, >, <=, >=
def three 1 + 2 end putobject 1 putobject 2
send :+ JIT mov $0x3,%eax retq Method inlining on JIT
3. Calling Ruby method
Method dispatch on Ruby VM foo.bar
Method dispatch on Ruby VM foo.bar Method search (slow)
Method dispatch on Ruby VM foo.bar Method search (slow) Ruby
method C function attr_reader alias Method entry Foo#bar
Method dispatch on Ruby VM foo.bar Method search (slow) Verify
cache Ruby method C function attr_reader alias Method entry Foo#bar has cache
Method dispatch on Ruby VM foo.bar Method search (slow) Verify
cache Ruby method C function attr_reader alias Method entry Foo#bar has cache redefined?
Method dispatch on Ruby VM foo.bar Method search (slow) Verify
cache Ruby method C function attr_reader alias Method entry Foo#bar has cache redefined?
Method dispatch on JIT foo.bar Verify cache Ruby method Method
entry Foo#bar has cache Cancel JIT! Less branches Less memory access redefined? some inlining
4. Instance variable access
Reading instance variable on VM @foo
Reading instance variable on VM @foo Search index (many branches,
slow)
Reading instance variable on VM @foo Search index (many branches,
slow) self.class. instance_variables[index = 2]
Reading instance variable on VM Search index (many branches, slow)
self.class. instance_variables[index = 2] @foo has cache Verify cache
Reading instance variable on VM Search index (many branches, slow)
self.class. instance_variables[index = 2] @foo different class? has cache Verify cache
Reading instance variable on VM Search index (many branches, slow)
self.class. instance_variables[index = 2] @foo different class? has cache Verify cache
Reading instance variable on JIT self.class. instance_variables[2] @foo different class?
has cache Verify cache Cancel JIT! inlined index Less branches Less memory access
Summary: When JIT makes Ruby fast Optcarrot Rails 1. Almost
all methods ✓ ✓ 2. Basic operators on core classes ✓ 3. Calling Ruby method ✓ ✓ 4. Instance variable access ✓ ?
Future of Ruby's JIT
Will Ruby 2.6 be fast only on Optcarrot?
Future idea (not for 2.6) • Stack allocation of objects
- That requires "escape analysis" (not easy) - We haven't estimated its possible impact yet
Some rooms for improvements in 2.6 (!?) • Change heuristics
to trigger/compact JIT • Profile-guided optimization • Method inlining
How can we experiment them? Benchmark!
None
None
Create a benchmark for Ruby 3x3?
benchmark_driver.gem
None
None
None
None
Conclusion • Ruby 2.6.0-preview3 JIT is still early days -
Small --jit-max-cache might be an option for now • We still have chance to make Ruby 2.6.0 better - Benchmarks are wanted!!!