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
Rustでゴミ集め
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
monochrome
June 13, 2021
Programming
380
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rustでゴミ集め
プログラミング言語Slack 定期ミートアップ#2 2021/06/13
Rustでゴミ集め
monochrome
June 13, 2021
More Decks by monochrome
See All by monochrome
RubyKaigi2026: Invariants in my own Ruby
sisshiki1969
0
15
Improving my own Ruby thereafter
sisshiki1969
1
250
あなたとJIT, 今すぐアセンブ ル
sisshiki1969
1
1k
Improve my own Ruby
sisshiki1969
1
580
My own Ruby, thereafter
sisshiki1969
0
410
Running Optcarrot (faster) on my own Ruby.
sisshiki1969
1
320
仮想マシンにおけるスタックの管理
sisshiki1969
0
240
RustでつくるRubyのFiber
sisshiki1969
0
320
Shinjuku.rs#15 Rustでつくるx86アセンブラ
sisshiki1969
0
1.8k
Other Decks in Programming
See All in Programming
Webフレームワークの ベンチマークについて
yusukebe
0
190
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
290
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.6k
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
190
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
320
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
290
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.7k
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.8k
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
470
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
1
420
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.3k
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
360
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
Are puppies a ranking factor?
jonoalderson
1
3.7k
RailsConf 2023
tenderlove
30
1.5k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
270
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.2k
We Are The Robots
honzajavorek
0
270
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Tell your own story through comics
letsgokoyo
1
980
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
230
Transcript
プログラミング言語Slack 定期ミートアップ#2 2021/06/13 Rustでゴミ集め monochrome twitter: @s_isshiki1969
ruruby (https://github.com/sisshiki1969/ruruby) • 純Rust製のRuby実装 • 仮想マシンインタプリタ • 他の既存実装・仮想マシンへの依存なし • Rubyの標準ライブラリはRustで実装
• ガーベジコレクタを独自実装 • 2万行ぐらい
参考文献 Richard Jones et al. 翻訳監修:前田敦司 鵜川始陽 小宮 常康 翔泳社, 2016 中村成洋 相川光
秀和システム, 2010 moppris 技術書典5, 2016
Garbage collector Mutator (VM) Allocator ヒープ割り当て Collector 不要なオブジェクトの回収 割り当て要求 GC起動
*mut RValue
Rubyオブジェクトの内部表現 struct Value(std::num::NonZeroU64); struct RValue { class: Module, var_table: Option<Box<ValueTable>>,
kind: ObjKind, } (56 bytes) struct GCBox<T: GC> { inner: T, next: Option<GCBoxRef<T>>, } (64 bytes)
Page 0 7 8 15 16 20 23 4031 0x4_0000
20 mark bitmap 0 7 64b x 4032 slot
Allocator Free list
Allocator Free list
Collector 起動 Free list
Garbage collection: Mark local variables method Array local variables method
Hash K V K V K V K V Object Instance variables Free list
Garbage collection: Sweep local variables method Array local variables method
Hash K V K V K V K V Object Instance variables Free list
Collector 処理終了 Free list mark bitmap
Allocator Free list
benchmark: aobench.rb (GC on / off)
バグりがちな点 var = [1, 2, 3].map { |x| x.to_s }
配列オブジェクトをイテレートし、 各要素を関数で処理して戻り値を集め 配列を作って返すRubyスクリプト
var = [1, 2, 3].map { |x| x.to_s }
①VM実行中にGCが起動すると… GC! ②作成中のオブジェクト が回収されてしまう ③VMは気づかず処理続行 → いつの間にか上書きされてバグる var = [1,
2, 3].map { |x| x.to_s }
まとめ • GCつくりました。 • GCバグるとつらい。