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
Curious Case of Ruby's memory
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Hemant Kumar
September 30, 2014
Programming
0
160
Curious Case of Ruby's memory
A roundup of Ruby memory profiling and GC
Hemant Kumar
September 30, 2014
Tweet
Share
More Decks by Hemant Kumar
See All by Hemant Kumar
introduction to dtrace
gnufied
3
190
Ruby 2.0 upcoming changes
gnufied
0
110
Building RESTful APIs
gnufied
13
1.2k
Ruby introduction for newbies
gnufied
8
1.1k
Other Decks in Programming
See All in Programming
Package Management Learnings from Homebrew
mikemcquaid
0
240
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
5
850
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
180
Best-Practices-for-Cortex-Analyst-and-AI-Agent
ryotaroikeda
1
120
CSC307 Lecture 10
javiergs
PRO
1
680
Premier Disciplin for Micro Frontends Multi Version/ Framework Scenarios @OOP 2026, Munic
manfredsteyer
PRO
0
140
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
Gemini for developers
meteatamel
0
110
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
200
Apache Iceberg V3 and migration to V3
tomtanaka
0
190
アプリプラットフォームにおける、レガシー基盤刷新の戦略
masaki12
0
110
PJのドキュメントを全部Git管理にしたら、一番喜んだのはAIだった
nanaism
0
130
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
130
Thoughts on Productivity
jonyablonski
74
5k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.9k
Heart Work Chapter 1 - Part 1
lfama
PRO
5
35k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.7k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
360
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
140
Claude Code のすすめ
schroneko
67
210k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.6k
Transcript
Curious case of Ruby’s memory
Garbage Collection
How it used to work
Mark and Sweep
None
Generational GC
Most objects die Young
None
active_users[user.id] = user Old gen object New object
Bug!
None
None
memcpy(RARRAY_PTR(ary)[i], src, array_len(src)) Copy into ruby array Object in old
gen
None
None
Key take aways
Don’t use low level access for Ruby DS in C
extensions, such RARRAY_PTR
If your C-ext holds ref. to a Ruby object you
need Write Barriers for taking adv. of Gen. GC.
GC Tuning via ENV variables
Part 2
Memory Profiling Ruby apps
None
Thanks to Ruby 2.1
RBKit
None
None
None
None
RBkit Team • Emil • Kashyap • Yuva • Hemant
And
http://codemancers.com
C is what Linus Torvalds wrote.
About RBKit • A low overhead Ruby Profiler built for
MRI. • Written almost completely in C.
RBKit • A Desktop application • A Ruby gem
RBKit • Gather and send all profile data via ZeroMQ
to connected client (Desktop app) • Uses msgpack as serialization format.
Advantage RBKit • ZeroMQ manages separate IO threads for sending
and receiving messages. • Msgpack serialisation is fast. • A profiler that can be used in production!
Using it ! require 'rbkit' ! Rbkit.start_profiling
RbkitApp
RbkitApp • Cross platform - Qt/C++ • Webkit/Javascript for rendering
charts. • Sqlite
Why Qt/C++? • All heavy lifting is done client side.
• Parsing and processing heap dump of millions of objects. • We can still render certain pages/data using plain HTML via Qt Webkit bridge.
Tools used • Valgrind • leaks (Try this command on
OSX now!)
RBkit Status Report • Memory Profiling works (Demo) • CPU
Profiling is in works. • Open source
RbkitApp Demo
GC tuning visualizations
RUBY_GC_HEAP_INIT_SLOTS
RUBY_GC_HEAP_GROWTH_FACTOR
Ruby Heap vs C heap • Rvalue size = 40
bytes • If Object can’t fit that size, ruby uses ruby_xmalloc() • which is wrapper around malloc()
RUBY_GC_MALLOC_LIMIT
Thank you! • https://github.com/code-mancers/rbkit • https://github.com/code-mancers/rbkit- client • http://thorstenball.com/blog/2014/03/12/ watching-understanding-ruby-2.1-garbage-
collector/ • http://tmm1.net/ruby21-rgengc/
@gnufied http://www.codemancers.com Hemant Kumar