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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Hemant Kumar
September 30, 2014
Programming
170
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Curious Case of Ruby's memory
A roundup of Ruby memory profiling and GC
Hemant Kumar
September 30, 2014
More Decks by Hemant Kumar
See All by Hemant Kumar
introduction to dtrace
gnufied
3
200
Ruby 2.0 upcoming changes
gnufied
0
130
Building RESTful APIs
gnufied
13
1.2k
Ruby introduction for newbies
gnufied
8
1.1k
Other Decks in Programming
See All in Programming
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
230
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
dRuby over BLE
makicamel
2
340
JJUG CCC 2026 Spring: JSpecify で実現する Kotlin フレンドリーな Java API 設計
ternbusty
1
170
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
280
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
340
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
540
ふつうのFeature Flag実践入門
irof
7
3.9k
net-httpのHTTP/2対応について
naruse
0
480
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
260
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
160
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
260
Featured
See All Featured
The SEO Collaboration Effect
kristinabergwall1
1
480
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
310
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
360
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
530
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
720
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
580
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