$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RustでつくるRubyのFiber
Search
monochrome
October 22, 2020
Programming
0
510
RustでつくるRubyのFiber
Fukuoka.rs vol.7 ONLINE
https://fukuokars.connpass.com/event/191881/
monochrome
October 22, 2020
Tweet
Share
More Decks by monochrome
See All by monochrome
Improving my own Ruby thereafter
sisshiki1969
1
190
あなたとJIT, 今すぐアセンブ ル
sisshiki1969
1
880
Improve my own Ruby
sisshiki1969
1
400
My own Ruby, thereafter
sisshiki1969
0
350
Running Optcarrot (faster) on my own Ruby.
sisshiki1969
1
250
仮想マシンにおけるスタックの管理
sisshiki1969
0
210
Rustでゴミ集め
sisshiki1969
1
340
RustでつくるRubyのFiber
sisshiki1969
0
300
Shinjuku.rs#15 Rustでつくるx86アセンブラ
sisshiki1969
0
1.7k
Other Decks in Programming
See All in Programming
宅宅自以為的浪漫:跟 AI 一起為自己辦的研討會寫一個售票系統
eddie
0
480
手軽に積ん読を増やすには?/読みたい本と付き合うには?
o0h
PRO
1
160
[堅牢.py #1] テストを書かない研究者に送る、最初にテストを書く実験コード入門 / Let's start your ML project by writing tests
shunk031
12
7k
AI時代もSEOを頑張っている話
shirahama_x
0
260
Developing static sites with Ruby
okuramasafumi
0
190
CloudNative Days Winter 2025: 一週間で作る低レイヤコンテナランタイム
ternbusty
7
2k
30分でDoctrineの仕組みと使い方を完全にマスターする / phpconkagawa 2025 Doctrine
ttskch
3
780
Level up your Gemini CLI - D&D Style!
palladius
1
180
S3 VectorsとStrands Agentsを利用したAgentic RAGシステムの構築
tosuri13
6
290
AIエージェントを活かすPM術 AI駆動開発の現場から
gyuta
0
300
GeistFabrik and AI-augmented software development
adewale
PRO
0
280
複数人でのCLI/Infrastructure as Codeの暮らしを良くする
shmokmt
5
2.2k
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Become a Pro
speakerdeck
PRO
30
5.7k
It's Worth the Effort
3n
187
29k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
YesSQL, Process and Tooling at Scale
rocio
174
15k
[RailsConf 2023] Rails as a piece of cake
palkan
58
6.1k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Designing for humans not robots
tammielis
254
26k
GraphQLとの向き合い方2022年版
quramy
50
14k
Java REST API Framework Comparison - PWX 2021
mraible
34
9k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
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/