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
310
Rustでゴミ集め
プログラミング言語Slack 定期ミートアップ#2 2021/06/13
Rustでゴミ集め
monochrome
June 13, 2021
Tweet
Share
More Decks by monochrome
See All by monochrome
Improve my own Ruby
sisshiki1969
0
100
My own Ruby, thereafter
sisshiki1969
0
300
Running Optcarrot (faster) on my own Ruby.
sisshiki1969
1
200
仮想マシンにおけるスタックの管理
sisshiki1969
0
190
RustでつくるRubyのFiber
sisshiki1969
0
260
Shinjuku.rs#15 Rustでつくるx86アセンブラ
sisshiki1969
0
1.6k
fukuoka.rb#202 RustでつくるRuby
sisshiki1969
1
790
RustでつくるRubyのFiber
sisshiki1969
0
480
Rustでつくるガーベジコレクタ
sisshiki1969
0
670
Other Decks in Programming
See All in Programming
AIコーディングの理想と現実
tomohisa
35
37k
状態と共に暮らす:ステートフルへの挑戦
ypresto
3
1.1k
Memory API : Patterns, Performance et Cas d'Utilisation
josepaumard
1
170
Laravel × Clean Architecture
bumptakayuki
PRO
0
140
一緒に働きたくなるプログラマの思想 #QiitaConference
mu_zaru
78
20k
KANNA Android の技術的課題と取り組み
watabee
0
190
ニーリーQAのこれまでとこれから
nealle
2
170
REALITY コマンド作成チュートリアル
nishiuriraku
0
120
Optimizing JRuby 10
headius
0
570
エンジニア向けCursor勉強会 @ SmartHR
yukisnow1823
3
12k
State of Namespace
tagomoris
5
2.4k
Orleans + Sekiban + SignalR でリアルタイムWeb作ってみた
tomohisa
0
230
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
41
2.3k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
RailsConf 2023
tenderlove
30
1.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.7k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.2k
Music & Morning Musume
bryan
47
6.5k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.3k
Done Done
chrislema
184
16k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Intergalactic Javascript Robots from Outer Space
tanoku
271
27k
Testing 201, or: Great Expectations
jmmastey
42
7.5k
Raft: Consensus for Rubyists
vanstee
137
6.9k
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バグるとつらい。