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
340
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
180
あなたとJIT, 今すぐアセンブ ル
sisshiki1969
1
860
Improve my own Ruby
sisshiki1969
1
380
My own Ruby, thereafter
sisshiki1969
0
340
Running Optcarrot (faster) on my own Ruby.
sisshiki1969
1
250
仮想マシンにおけるスタックの管理
sisshiki1969
0
210
RustでつくるRubyのFiber
sisshiki1969
0
290
Shinjuku.rs#15 Rustでつくるx86アセンブラ
sisshiki1969
0
1.7k
fukuoka.rb#202 RustでつくるRuby
sisshiki1969
1
830
Other Decks in Programming
See All in Programming
Core MIDI を勉強して作曲用の電子ピアノ作ってみた!
hypebeans
0
110
MCPサーバー「モディフィウス」で変更容易性の向上をスケールする / modifius
minodriven
8
1.4k
Introducing RemoteCompose: break your UI out of the app sandbox.
camaelon
2
540
Vueで学ぶデータ構造入門 リンクリストとキューでリアクティビティを捉える / Vue Data Structures: Linked Lists and Queues for Reactivity
konkarin
1
180
SidekiqでAIに商品説明を生成させてみた
akinko_0915
0
130
Stay Hacker 〜九州で生まれ、Perlに出会い、コミュニティで育つ〜
pyama86
1
690
Bakuraku E2E Scenario Test System Architecture #bakuraku_qa_study
teyamagu
PRO
0
710
仕様がそのままテストになる!Javaで始める振る舞い駆動開発
ohmori_yusuke
6
3.2k
モビリティSaaSにおけるデータ利活用の発展
nealle
0
110
퇴근 후 1억이 거래되는 서비스 만들기 | 내가 AI를 사용하는 방법
maryang
2
550
自動テストを活かすためのテスト分析・テスト設計の進め方/JaSST25 Shikoku
goyoki
2
610
AI駆動開発カンファレンスAutumn2025 _AI駆動開発にはAI駆動品質保証
autifyhq
0
150
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
72
12k
4 Signs Your Business is Dying
shpigford
186
22k
The Cult of Friendly URLs
andyhume
79
6.7k
Reflections from 52 weeks, 52 projects
jeffersonlam
355
21k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.6k
KATA
mclloyd
PRO
32
15k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
1.8k
How GitHub (no longer) Works
holman
315
140k
BBQ
matthewcrist
89
9.9k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.8k
Practical Orchestrator
shlominoach
190
11k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.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バグるとつらい。