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
Tuning Ruby's GC
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
George Ogata
August 21, 2013
Programming
61
1
Share
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
Building on Bluesky's AT Protocol with Ruby
mackuba
0
120
AI時代だからこそ「Bloc」を採用する価値があるのかもしれない
takuroabe
0
170
JCON - Create Agentic AI Apps, The Easy Way!
kdubois
1
110
ソースコード→AST→オペコード、の旅を覗いてみる
o0h
PRO
1
130
エラー処理の温故知新 / history of error handling technic
ryotanakaya
7
1.9k
Claude CodeでETLジョブ実行テストを自動化してみた
yoshikikasama
0
1.2k
ソフトウェア設計の結合バランス #phperkaigi
kajitack
0
510
過去のレビュー知見をSkillsで資産化した話
pkshadeck
PRO
1
1.9k
20260514 - build with ai 2026 - build LINE Bot with Gemini CLI
line_developers_tw
PRO
0
440
How We Practice Exploratory Testing in Iterative Development( #scrumniigata ) / 反復開発の中で、探索的テストをどう実施しているか
teyamagu
PRO
3
820
20260514_its_the_context_window_stupid.pdf
heita
0
990
【ディップ|26年新卒研修資料】TDD実装演習
dip_tech
PRO
0
180
Featured
See All Featured
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
530
Fireside Chat
paigeccino
42
3.9k
Thoughts on Productivity
jonyablonski
76
5.1k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
190
How to build a perfect <img>
jonoalderson
1
5.5k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Discover your Explorer Soul
emna__ayadi
2
1.1k
エンジニアに許された特別な時間の終わり
watany
106
240k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
Balancing Empowerment & Direction
lara
6
1.1k
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