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
Tuning Ruby's GC
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
George Ogata
August 21, 2013
Programming
69
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Tuning Ruby's GC
A recipe for tuning MRI's GC, plus a shallow tour of how allocation and collection works.
George Ogata
August 21, 2013
Other Decks in Programming
See All in Programming
最近”作らせてる” ローカルAIアプリの話
akit37
0
470
[Dev Group Paris Octobre 26] Agentforce, SIforce, Claudeforce, Slackbot… on s'y retrouve ?
nabondance
0
110
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
380
TechTown - Creating Composable Callables in Contemporary C++
rollbear
0
130
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
270
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
カツオ、ご期待ください
suneo3476
0
190
Workers Cache を知る
syumai
0
360
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2k
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
220
contenteditable と日本語入力に向き合う
colorful12
0
200
golang-bob.pdf
iwatsukayura
0
130
Featured
See All Featured
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
570
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
360
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
730
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.2k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
750
The Invisible Side of Design
smashingmag
301
52k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
43k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Transcript
Tuning Ruby’s GC A recipe 1 Wednesday, August 21, 13
Deploy of Doom 2 Wednesday, August 21, 13
Performance hog No documentation Tons of blogs Black magic Ruby’s
GC 3 Wednesday, August 21, 13
37 Signals (REE) GC_MALLOC_LIMIT 59,000,000 HEAP_MIN_SLOTS 600,000 FREE_MIN 100,000 (Years
ago) 4 Wednesday, August 21, 13
Twitter (Ruby 1.8.6) GC_MALLOC_LIMIT 50,000,000 HEAP_MIN_SLOTS 500,000 HEAP_SLOTS_ GROWTH_FACTOR 1
HEAP_SLOTS_INCREMENT 250,000 (April 2009) 5 Wednesday, August 21, 13
Not very satisfying... Let’s be methodical And automate it! 6
Wednesday, August 21, 13
Ruby Objects Immediates: Symbol, Fixnum, true, false, nil Everything else:
pointer to RObject flags klass ...data... ...data... ...data... 7 Wednesday, August 21, 13
Ruby Objects Immediates: Symbol, Fixnum, true, false, nil Everything else:
pointer to RObject flags klass len ptr capacity ...buffer... 7 Wednesday, August 21, 13
$ ruby X heaps Yi object slots 8 Wednesday, August
21, 13
$ ruby X heaps Yi object slots freelist 8 Wednesday,
August 21, 13
Allocation def allocate if freelist empty run gc if freelist
still empty allocate new heap object = freelist.pop # may malloc() set_up_object(object) object 9 Wednesday, August 21, 13
Collection def gc for each root mark(root) sweep() def mark(object)
if object not yet marked mark object object.mark() def sweep for each heap for each object in heap if object not marked add object to freelist object.free() 10 Wednesday, August 21, 13
Adaptation next_heaps_length = heaps_used * initial_growth_factor malloc_limit += (inc -
malloc_limit) * num_live_objects / num_objects free_min = heaps_used * HEAP_OBJ_LIMIT * 0.2 11 Wednesday, August 21, 13
Tuning Knobs GC_MALLOC_LIMIT 8,000,000 HEAP_MIN_SLOTS 10,000 FREE_MIN 4,096 HEAP_SLOTS_ GROWTH_FACTOR
1.8 12 Wednesday, August 21, 13
Your App GC_MALLOC_LIMIT ? HEAP_MIN_SLOTS ? FREE_MIN ? HEAP_SLOTS_ GROWTH_FACTOR
? 13 Wednesday, August 21, 13
Where do we want to be? 14 Wednesday, August 21,
13
Where do we want to be? 14 Wednesday, August 21,
13
gdb `which ruby` PID (gdb) p ruby_current_vm->objspace->malloc_params $1 = {limit
= 60609413, increase = 9542176} (gdb) p ruby_current_vm->objspace->heap $2 = {increment = 0, ptr = 0x14b325f0, sweep_slots = 0x0, sorted = 0x15686ac0, length = 8377, used = 8291, freelist = 0x9f45138, range = {0xa48c10, 0x1a997978}, freed = 0x0, live_num = 733492, free_num = 2642474, free_min = 678203, final_num = 0, do_heap_free = 2204162} 15 Wednesday, August 21, 13
gdb `which ruby` PID (gdb) p ruby_current_vm->objspace->malloc_params $1 = {limit
= 60609413, increase = 9542176} (gdb) p ruby_current_vm->objspace->heap $2 = {increment = 0, ptr = 0x14b325f0, sweep_slots = 0x0, sorted = 0x15686ac0, length = 8377, used = 8291, freelist = 0x9f45138, range = {0xa48c10, 0x1a997978}, freed = 0x0, live_num = 733492, free_num = 2642474, free_min = 678203, final_num = 0, do_heap_free = 2204162} HEAP_MIN_SLOTS = heap.length * 16384 / 40 15 Wednesday, August 21, 13
HowAboutWe (ruby 1.9.2) GC_MALLOC_LIMIT 59,000,000 HEAP_MIN_SLOTS 3,125,000 FREE_MIN 565,000 (August
2012) 16 Wednesday, August 21, 13
Better! 17 Wednesday, August 21, 13
GC::Profiler.enable COW-friendliness Lazy sweep GC 2.0 18 Wednesday, August 21,
13
Thanks! George Ogata @gogata oggy
[email protected]
Slides: http://speakerdeck.com/oggy/tuning-rubys-gc HowAboutWe We’re
Hiring! 19 Wednesday, August 21, 13