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
Mark Compact GC in MRI
Search
Aaron Patterson
June 13, 2017
Technology
4
1k
Mark Compact GC in MRI
My presentation about Mark Compact GC in MRI for GitHub Constellation Tokyo
Aaron Patterson
June 13, 2017
Tweet
Share
More Decks by Aaron Patterson
See All by Aaron Patterson
Speeding up Instance Variables in Ruby 3.3
tenderlove
1
310
[Feature #20425] Speeding up delegate methods
tenderlove
3
190
RailsConf 2023
tenderlove
29
940
Don't @ Me! Faster Instance Variables with Object Shapes
tenderlove
1
400
RailsConf 2022 Keynote
tenderlove
2
490
Some Assembly Required
tenderlove
1
510
HexDevs 2021
tenderlove
1
370
Compacting GC for MRI
tenderlove
60
4.4k
But At What Cost?
tenderlove
9
14k
Other Decks in Technology
See All in Technology
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
150
KnowledgeBaseDocuments APIでベクトルインデックス管理を自動化する
iidaxs
1
250
生成AIをより賢く エンジニアのための RAG入門 - Oracle AI Jam Session #20
kutsushitaneko
4
200
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
120
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
160
Wantedly での Datadog 活用事例
bgpat
1
380
社外コミュニティで学び社内に活かす共に学ぶプロジェクトの実践/backlogworld2024
nishiuma
0
250
AIのコンプラは何故しんどい?
shujisado
1
190
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
140
第3回Snowflake女子会_LT登壇資料(合成データ)_Taro_CCCMK
tarotaro0129
0
180
AI時代のデータセンターネットワーク
lycorptech_jp
PRO
1
280
alecthomas/kong はいいぞ / kamakura.go#7
fujiwara3
1
300
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Fireside Chat
paigeccino
34
3.1k
BBQ
matthewcrist
85
9.4k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
GraphQLとの向き合い方2022年版
quramy
44
13k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
The Language of Interfaces
destraynor
154
24k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Transcript
How people build software ! " Mark Compact GC in
MRI
How people build software ! ͜Μʹͪʂʂʂ 2
How people build software ! ࣗݾհ 3
How people build software ! ΞʔϩϯͰ͢ɻ! 4
How people build software ! ˏtenderlove 5
How people build software ! ! ˏtenderlove 6
How people build software ! ఱက͕େ͖Ͱɺ 7 ఱကϥϒΛݺΜͰ͍͍Ͱ͢
How people build software ! Ruby Core Team Rails Core
Team 8
How people build software ! ຊޠೳྗࢼݧ 9
How people build software ! ೣɺೋඖ 10
How people build software ! 11 SEATAC Airport Facebook YouTube
How people build software ! 12
How people build software ! 13 Gorbachev Puff Puff Thunderhorse
ΰϒͪΌΜ
How people build software ! GitHub ͷࣾһ 14
How people build software ! Ruby & Rails Developer 15
How people build software ! GitHub & OSS 16
How people build software ! ! GitHub Core Values 17
• Collaboration • Empathy • Quality • Positive Impact • Shipping
How people build software ! Collaboration 18 !
How people build software ! Empathy 19 !
How people build software ! Quality 20 !
How people build software ! Positive Impact 21 !
How people build software ! Shipping 22 !
How people build software ! GitHub ❤ OSS 23 !
How people build software ! GitHub & OSS 24 !
How people build software ! Mark / Compact GC 25
How people build software ! Mark / Compact GC 26
How people build software ! ! Roadmap 27 Ξϩέʔγϣϯ ίϨΫγϣϯ
ίϯύΫτ
How people build software ! Ξϩέʔγϣϯ 28
How people build software ! ! Ξϩέʔγϣϯ 29 def hoge
loop do Object.new end end hoge
How people build software ! Ξϩέʔγϣϯ GCͷ 30
How people build software ! `rb_newobj` in gc.c 31
How people build software ! ! ϝϞϦྖҬͷϨΠΞτ 32 ώʔϓྖҬ ϖʔδ
ϖʔδ ϖʔδ ϖʔδ ϖʔδ ϖʔδ ϖʔδ ϖʔδ Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj
How people build software ! Free Space = "Fast Path"
33
How people build software ! New Page = "Slow Path"
34
How people build software ! ! ϖʔδͷϨΠΞτ 35 ϖʔδ FREE
FREE FREE FREE FREE FREE FREE FREE FREE FREE SLOTS Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj
How people build software ! ! ϖʔδͷϨΠΞτ 36 ϖʔδ FREE
FREE FREE FREE FREE FREE FREE FREE FREE FREE SLOTS Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj
How people build software ! ཁ 37
How people build software ! heap has_many :pages 38
How people build software ! page has_many :slots 39
How people build software ! slot.is_a?(Empty) || slot.is_a?(Object) 40
How people build software ! ίϨΫγϣϯ 41
How people build software ! ϚʔΫεΠʔϓ GC Mark Sweep GC
42 !
How people build software ! ϚʔΫεΠʔϓͷ ΞϧΰϦζϜ 43
How people build software ! ! Tree of Objects 44
Root A B C D a = [ { c: 'd' } ] Ruby Array Hash String Symbol
How people build software ! ! Tree of Objects 45
Root A B C D a = [ { c: 'd' } ] a = nil Ruby
How people build software ! ϚʔΫɹεΠʔϓ 46 ͔ͩΒʮϚʔΫεΠʔϓʯɹ tenderlove
How people build software ! ! Mark Phase 47 Root
D A B C F E H G
How people build software ! ! Mark Phase 48 Root
D A B C F E H G
How people build software ! ! Mark Phase 49 Root
D A B C F E H G
How people build software ! ! Mark Phase 50 Root
D A B C F E H G
How people build software ! Incremental / Lazy 51
How people build software ! ίϯύΫγϣϯͷؔ 52
How people build software ! ! Free Space 53 ϖʔδ
FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj ϖʔδ FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj ϖʔδ FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj
How people build software ! ! Free Space 54 FREE
FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj
How people build software ! ! Free Space 55 FREE
FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj FREE FREE FREE FREE FREE FREE FREE FREE FREE FREE Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj Obj
How people build software ! ΦϒδΣΫτҠಈग़དྷͳ͍ 56
How people build software ! ίϯύΫγϣϯͱ 57
How people build software ! github.com/github/ruby/tree/gc-compact 58
How people build software ! ίϯύΫγϣϯͷ ΞϧΰϦζϜ 59
How people build software ! "2 Finger Compaction" 60 ☝
☝
How people build software ! ! Compaction Steps 61 ΦϒδΣΫτͷҠಈ
ϦϑΝϨϯεͷߋ৽
How people build software ! ! ΦϒδΣΫτͷҠಈ 62 1 2
3 4 5 6 7 8 9 a b Free Free Free Obj Free Obj Obj Obj Free Free Obj ☝ ☝ Free Pointer Scan Pointer 1 2 3 5 Done! Address Heap
How people build software ! ! ΦϒδΣΫτҠಈͷલ 63 1 2
3 4 5 6 7 8 9 a b Free Free Free Obj Free Obj Obj Obj Free Free Obj Address Heap a = { c: 'd' } Ruby {} :c 'd'
How people build software ! ! ΦϒδΣΫτҠಈͷޙ 64 1 2
3 4 5 6 7 8 9 a b Obj Free Obj Obj Obj Free Free Obj Address Heap a = { c: 'd' } Ruby {} :c 'd' 1 2 3 5
How people build software ! ! ϦϑΝϨϯεͷߋ৽ 65 1 2
3 4 5 6 7 8 9 a b Obj Obj Obj Obj Free Free Obj Address Heap a = { c: 'd' } Ruby {} :c 'd' 1 2 3 5 ☝ Done!
How people build software ! ! ϦϑΝϨϯεͷߋ৽ 66 1 2
3 4 5 6 7 8 9 a b Obj Obj Obj Obj Free Free Obj Address Heap a = { c: 'd' } Ruby {} :c 'd' 1 2 3 5 Free Free Free Free
How people build software ! ίϯύΫτྃʂʂ 67
How people build software ! ίϯύΫγϣϯͷ 68
How people build software ! ! ී௨ͷϦϑΝϨϯε 69 Hash Symbol
String C code
How people build software ! ! C֦ுͷϦϑΝϨϯε 70 Hash Symbol
String C code rb_gc_mark ෆҠಈ Ҡಈ Ҡ ಈ
How people build software ! άϩόϧม 71
How people build software ! ! file.c in MRI 72
separator = rb_obj_freeze(rb_usascii_str_new2("/")); /* separates directory parts in path */ rb_define_const(rb_cFile, "Separator", separator); rb_define_const(rb_cFile, "SEPARATOR", separator); static VALUE rb_file_s_join(VALUE klass, VALUE args) { return rb_file_join(args, separator); } άϩόϧม
How people build software ! ! άϩόϧม - SEGV 73
$ ruby -e'File::Separator = File::SEPARATOR = nil; GC.start; File.join("a", "b")' # BOOM $ jruby -e'File::Separator = File::SEPARATOR = nil; GC.start; File.join("a", "b")'
How people build software ! General Problem 74
How people build software ! ݁Ռ 75
How people build software ! Rails Heap 76
How people build software ! ! Compaction Code 77 GC.start
File.open("pre_compact.json", "wb") { |f| ObjectSpace.dump_all(output: f) } GC.start p GC.compact GC.start File.open("post_compact.json", "wb") { |f| ObjectSpace.dump_all(output: f) } $ ruby bin/rails r script.rb
ίϯύΫτͷલ F U P Pages Number of slots 0 100
200 300 400
ίϯύΫτͷޙ F U P Pages Number of slots 0 100
200 300 400
How people build software ! ίϯύΫτͷલ: 528 / 552 80
How people build software ! ίϯύΫτͷޙ: 167 / 552 81
How people build software ! ͰɺվળͰ͖·͢ 82
How people build software ! GitHub Heap Graphs 83
None
How people build software ! ·ͱΊ 85 !
How people build software ! Why Compact? 86 !
How people build software ! OSS Software https://github.com/github/ruby/tree/gc-compact 87 !
How people build software ! ͋Γ͕ͱ͏͍͟͝·͢ʂ 88
How people build software ! "