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
monochrome
June 13, 2021
Programming
1
360
Rustでゴミ集め
プログラミング言語Slack 定期ミートアップ#2 2021/06/13
Rustでゴミ集め
monochrome
June 13, 2021
Tweet
Share
More Decks by monochrome
See All by monochrome
Improving my own Ruby thereafter
sisshiki1969
1
210
あなたとJIT, 今すぐアセンブ ル
sisshiki1969
1
980
Improve my own Ruby
sisshiki1969
1
480
My own Ruby, thereafter
sisshiki1969
0
380
Running Optcarrot (faster) on my own Ruby.
sisshiki1969
1
290
仮想マシンにおけるスタックの管理
sisshiki1969
0
230
RustでつくるRubyのFiber
sisshiki1969
0
310
Shinjuku.rs#15 Rustでつくるx86アセンブラ
sisshiki1969
0
1.7k
fukuoka.rb#202 RustでつくるRuby
sisshiki1969
1
860
Other Decks in Programming
See All in Programming
「接続」—パフォーマンスチューニングの最後の一手 〜点と点を結ぶ、その一瞬のために〜
kentaroutakeda
3
1.9k
ロボットのための工場に灯りは要らない
watany
12
3.2k
夢の無限スパゲッティ製造機 -実装篇- #phpstudy
o0h
PRO
0
130
Agentic AI: Evolution oder Revolution
mobilelarson
PRO
0
190
ファインチューニングせずメインコンペを解く方法
pokutuna
0
180
The free-lunch guide to idea circularity
hollycummins
0
350
「効かない!」依存性注入(DI)を活用したAPI Platformのエラーハンドリング奮闘記
mkmk884
0
210
モダンOBSプラグイン開発
umireon
0
180
Linux Kernelの1文字のミスで 権限昇格ができた話
rqda
0
2.1k
我々はなぜ「層」を分けるのか〜「関心の分離」と「抽象化」で手に入れる変更に強いシンプルな設計〜 #phperkaigi / PHPerKaigi 2026
shogogg
2
450
[SF Ruby Feb'26] The Silicon Heel
palkan
0
130
Angular-Apps smarter machen mit Gen AI: Lokal und offlinefähig - Hands-on Workshop!
christianliebel
PRO
0
140
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
515
110k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
200
Scaling GitHub
holman
464
140k
How GitHub (no longer) Works
holman
316
150k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.4k
The Curious Case for Waylosing
cassininazir
0
280
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
400
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
150
Paper Plane (Part 1)
katiecoart
PRO
0
5.9k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
590
Git: the NoSQL Database
bkeepers
PRO
432
67k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1k
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バグるとつらい。