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
350
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
200
あなたとJIT, 今すぐアセンブ ル
sisshiki1969
1
920
Improve my own Ruby
sisshiki1969
1
430
My own Ruby, thereafter
sisshiki1969
0
360
Running Optcarrot (faster) on my own Ruby.
sisshiki1969
1
270
仮想マシンにおけるスタックの管理
sisshiki1969
0
220
RustでつくるRubyのFiber
sisshiki1969
0
300
Shinjuku.rs#15 Rustでつくるx86アセンブラ
sisshiki1969
0
1.7k
fukuoka.rb#202 RustでつくるRuby
sisshiki1969
1
840
Other Decks in Programming
See All in Programming
ゆくKotlin くるRust
exoego
1
200
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.5k
.NET Conf 2025 の興味のあるセッ ションを復習した / dotnet conf 2025 quick recap for backend engineer
tomohisa
0
110
AI時代を生き抜く 新卒エンジニアの生きる道
coconala_engineer
1
540
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
0
570
CSC307 Lecture 04
javiergs
PRO
0
640
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
440
生成AIを利用するだけでなく、投資できる組織へ
pospome
2
450
AIエージェントの設計で注意するべきポイント6選
har1101
6
3.1k
CSC307 Lecture 05
javiergs
PRO
0
470
The Art of Re-Architecture - Droidcon India 2025
siddroid
0
160
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
310
Featured
See All Featured
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
420
Mind Mapping
helmedeiros
PRO
0
49
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Building Adaptive Systems
keathley
44
2.9k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
250
Into the Great Unknown - MozCon
thekraken
40
2.2k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
140
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.5k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
270
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
65
35k
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バグるとつらい。