Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Curious Case of Ruby's memory
Search
Hemant Kumar
September 30, 2014
Programming
0
150
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
180
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
大規模Cloud Native環境におけるFalcoの運用
owlinux1000
0
130
AIコーディングエージェント(skywork)
kondai24
0
180
公共交通オープンデータ × モバイルUX 複雑な運行情報を 『直感』に変換する技術
tinykitten
PRO
0
120
TestingOsaka6_Ozono
o3
0
170
俺流レスポンシブコーディング 2025
tak_dcxi
14
8.9k
Tinkerbellから学ぶ、Podで DHCPをリッスンする手法
tomokon
0
140
堅牢なフロントエンドテスト基盤を構築するために行った取り組み
shogo4131
8
2.4k
これならできる!個人開発のすゝめ
tinykitten
PRO
0
120
認証・認可の基本を学ぼう前編
kouyuume
0
260
Go コードベースの構成と AI コンテキスト定義
andpad
0
130
AIコーディングエージェント(Manus)
kondai24
0
200
안드로이드 9년차 개발자, 프론트엔드 주니어로 커리어 리셋하기
maryang
1
120
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Optimizing for Happiness
mojombo
379
70k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
85
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
We Are The Robots
honzajavorek
0
110
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
500
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.3k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
0
21
The agentic SEO stack - context over prompts
schlessera
0
550
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