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
300
Rustでゴミ集め
プログラミング言語Slack 定期ミートアップ#2 2021/06/13
Rustでゴミ集め
monochrome
June 13, 2021
Tweet
Share
More Decks by monochrome
See All by monochrome
My own Ruby, thereafter
sisshiki1969
0
270
Running Optcarrot (faster) on my own Ruby.
sisshiki1969
1
170
仮想マシンにおけるスタックの管理
sisshiki1969
0
180
RustでつくるRubyのFiber
sisshiki1969
0
250
Shinjuku.rs#15 Rustでつくるx86アセンブラ
sisshiki1969
0
1.6k
fukuoka.rb#202 RustでつくるRuby
sisshiki1969
1
770
RustでつくるRubyのFiber
sisshiki1969
0
460
Rustでつくるガーベジコレクタ
sisshiki1969
0
640
Other Decks in Programming
See All in Programming
color-scheme: light dark; を完全に理解する
uhyo
5
390
Java Webフレームワークの現状 / java web framework at burikaigi
kishida
9
2.2k
JavaScriptツール群「UnJS」を5分で一気に駆け巡る!
k1tikurisu
9
1.8k
苦しいTiDBへの移行を乗り越えて快適な運用を目指す
leveragestech
0
630
昭和の職場からアジャイルの世界へ
kumagoro95
1
380
Djangoアプリケーション 運用のリアル 〜問題発生から可視化、最適化への道〜 #pyconshizu
kashewnuts
1
250
メンテが命: PHPフレームワークのコンテナ化とアップグレード戦略
shunta27
0
120
技術を根付かせる / How to make technology take root
kubode
1
250
さいきょうのレイヤードアーキテクチャについて考えてみた
yahiru
3
750
負債になりにくいCSSをデザイナとつくるには?
fsubal
10
2.4k
PHP ステートレス VS ステートフル 状態管理と並行性 / php-stateless-stateful
ytake
0
100
Amazon Q Developer Proで効率化するAPI開発入門
seike460
PRO
0
110
Featured
See All Featured
A Tale of Four Properties
chriscoyier
158
23k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
630
Practical Orchestrator
shlominoach
186
10k
Automating Front-end Workflow
addyosmani
1368
200k
Large-scale JavaScript Application Architecture
addyosmani
511
110k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
The Language of Interfaces
destraynor
156
24k
Faster Mobile Websites
deanohume
306
31k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
550
Scaling GitHub
holman
459
140k
What's in a price? How to price your products and services
michaelherold
244
12k
Building Your Own Lightsaber
phodgson
104
6.2k
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バグるとつらい。