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
0
460
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
My own Ruby, thereafter
sisshiki1969
0
270
Running Optcarrot (faster) on my own Ruby.
sisshiki1969
1
170
仮想マシンにおけるスタックの管理
sisshiki1969
0
180
Rustでゴミ集め
sisshiki1969
1
300
RustでつくるRubyのFiber
sisshiki1969
0
250
Shinjuku.rs#15 Rustでつくるx86アセンブラ
sisshiki1969
0
1.6k
fukuoka.rb#202 RustでつくるRuby
sisshiki1969
1
770
Rustでつくるガーベジコレクタ
sisshiki1969
0
640
Other Decks in Programming
See All in Programming
2024年のWebフロントエンドのふりかえりと2025年
sakito
3
250
pylint custom ruleで始めるレビュー自動化
shogoujiie
0
120
Open source software: how to live long and go far
gaelvaroquaux
0
640
Unity Android XR入門
sakutama_11
0
160
パスキーのすべて ── 導入・UX設計・実装の紹介 / 20250213 パスキー開発者の集い
kuralab
3
790
CI改善もDatadogとともに
taumu
0
120
Immutable ActiveRecord
megane42
0
140
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
160
GitHub Actions × RAGでコードレビューの検証の結果
sho_000
0
270
AWS Organizations で実現する、 マルチ AWS アカウントのルートユーザー管理からの脱却
atpons
0
150
Amazon Q Developer Proで効率化するAPI開発入門
seike460
PRO
0
110
Djangoアプリケーション 運用のリアル 〜問題発生から可視化、最適化への道〜 #pyconshizu
kashewnuts
1
250
Featured
See All Featured
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
4
330
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
Six Lessons from altMBA
skipperchong
27
3.6k
Designing on Purpose - Digital PM Summit 2013
jponch
117
7.1k
Unsuck your backbone
ammeep
669
57k
Bash Introduction
62gerente
611
210k
Speed Design
sergeychernyshev
27
790
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
175
51k
Faster Mobile Websites
deanohume
306
31k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
10
1.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.2k
Rebuilding a faster, lazier Slack
samanthasiow
80
8.8k
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/