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
230
Rustでゴミ集め
プログラミング言語Slack 定期ミートアップ#2 2021/06/13
Rustでゴミ集め
monochrome
June 13, 2021
Tweet
Share
More Decks by monochrome
See All by monochrome
仮想マシンにおけるスタックの管理
sisshiki1969
0
160
RustでつくるRubyのFiber
sisshiki1969
0
210
Shinjuku.rs#15 Rustでつくるx86アセンブラ
sisshiki1969
0
1.4k
fukuoka.rb#202 RustでつくるRuby
sisshiki1969
1
670
RustでつくるRubyのFiber
sisshiki1969
0
360
Rustでつくるガーベジコレクタ
sisshiki1969
0
530
Other Decks in Programming
See All in Programming
Fast JSX: Don't clone props object #28768
yossydev
1
130
Zero Waste, Radical Magic, and Italian Graft – Quarkus Efficiency Secrets
hollycummins
0
230
スキーマ駆動開発による品質とスピードの両立 - 私達は何故、スキーマを書くのか
kentaroutakeda
0
170
Kotlin Multiplatform at Stable and Beyond (Android Makers 2024)
zsmb
0
290
Anthropic Cookbook のおすすめレシピ
schroneko
7
980
初心者のためのRubyKaigi入門/RubyKaigi Introduction
a_matsuda
2
860
Behind VS Code Extensions for JavaScript / TypeScript Linnting and Formatting
unvalley
5
930
単体テストを書かない技術 #phpcon_odawara
o0h
PRO
27
8.3k
Milestoner
bkuhlmann
1
410
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
4
970
Site Reliability Engineering for GMO
pyama86
8
1k
MetricKitで予期せぬ終了を検知する話 / Detect unexpected termination with MetricKit
nekowen
1
190
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
PRO
18
6.9k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
The Cost Of JavaScript in 2023
addyosmani
16
3.9k
Side Projects
sachag
451
41k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
2
1.3k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
78
43k
It's Worth the Effort
3n
180
27k
VelocityConf: Rendering Performance Case Studies
addyosmani
320
23k
We Have a Design System, Now What?
morganepeng
43
6.8k
jQuery: Nuts, Bolts and Bling
dougneiner
59
7.1k
The Mythical Team-Month
searls
216
42k
Building a Scalable Design System with Sketch
lauravandoore
456
32k
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バグるとつらい。