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でつくるRubyのFiber
Search
monochrome
October 22, 2020
Programming
550
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RustでつくるRubyのFiber
Fukuoka.rs vol.7 ONLINE
https://fukuokars.connpass.com/event/191881/
monochrome
October 22, 2020
More Decks by monochrome
See All by monochrome
RubyKaigi2026: Invariants in my own Ruby
sisshiki1969
0
15
Improving my own Ruby thereafter
sisshiki1969
1
250
あなたとJIT, 今すぐアセンブ ル
sisshiki1969
1
1k
Improve my own Ruby
sisshiki1969
1
580
My own Ruby, thereafter
sisshiki1969
0
410
Running Optcarrot (faster) on my own Ruby.
sisshiki1969
1
320
仮想マシンにおけるスタックの管理
sisshiki1969
0
240
Rustでゴミ集め
sisshiki1969
1
380
RustでつくるRubyのFiber
sisshiki1969
0
320
Other Decks in Programming
See All in Programming
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
200
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
290
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
150
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
210
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
270
OS アップデート対応の取り組み方がもっと共有されてほしい
andpad
0
110
Contextとはなにか
chiroruxx
1
390
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
260
Creating Composable Callables in Contemporary C++
rollbear
0
180
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
130
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
230
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
280
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
880
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
340
HDC tutorial
michielstock
2
730
The Mindset for Success: Future Career Progression
greggifford
PRO
0
370
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1k
Scaling GitHub
holman
464
140k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
320
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
230
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Transcript
RustでつくるRubyのFiber monochrome twitter: @s_isshiki1969 Slack: プログラミング言語処理系が好きな人の集まり https://prog-lang-sys-ja-slack.github.io/wiki/
Agenda • RustでRubyの処理系を作っています。 • 小さなプログラムは程度動くようになってきたので、大きなアプリケーションを動か せるよう頑張りました。 • その過程でsync_channelを使って協調スレッド(コルーチン)を実装したので発表し ます。
• 動的型付けのオブジェクト指向言語 • クラス定義、メソッド定義など、全てが動的 • 豊富なメタ言語機能 • Cで書かれている(50万行ぐらい)。 Ruby
既存のRuby実装(開発継続中のもの) 名称 記述言語 実行基盤 CRuby(MRI) C 独自VM mruby C 独自VM
JRuby Java JVM TruffleRuby Java GraalVM (JVM) Opal Ruby JSへコンパイル Rubinius C++, Ruby 独自VM Topaz RPython PyPy Artichoke Rust mruby ruruby Rust 独自VM
ruruby (https://github.com/sisshiki1969/ruruby) • 純Rust製のRuby実装 • 仮想マシンインタプリタ • 他の既存実装・仮想マシンへの依存なし • Rubyの標準ライブラリはRustで実装
• ガーベジコレクタを独自実装 • 2万行ぐらい
構成 virtual machine (VM) Rubyコード 抽象構文木 (AST) バイトコード parser codegen
1 1 2 3
benchmark ※CRuby(3.0.0-dev)と実行時間を比較。大きいほど遅い。
Optcarrot • Rubyで書かれたNESエミュレータ • 「Ruby3をRuby2の3倍速くする」目標のための準公式ベンチマーク • 実際にゲームができるモードと、ベンチマーク専用のモードがある • ベンチマークモードでは外部ライブラリを使用しない •
「普通のRuby」で書かれた標準モードと、コードを自己書き換えして高速化する最 適化モードがある • ≒6500 LOC repo: https://github.com/mame/optcarrot • 紹介スライド: https://www.slideshare.net/mametter/optcarrot-a-pureruby-nes-emulator
Fiber (coroutine in Ruby) f = Fiber.new { .. }
f.resume 処理A 処理B Fiber.yield f.resume 処理C Child Fiber 処理 処理 処理
sync_channelによるFiberの実装 https://github.com/sisshiki1969/ruruby/bl ob/aa72942d46337574448dafb493ee27 bb4defb69d/src/value/fiber.rs#L124
None
Optcarrot公式サイト
Slack: プログラミング言語処理系が好きな人の集まり https://prog-lang-sys-ja-slack.github.io/wiki/