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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
monochrome
October 22, 2020
Programming
0
530
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
210
あなたとJIT, 今すぐアセンブ ル
sisshiki1969
1
960
Improve my own Ruby
sisshiki1969
1
470
My own Ruby, thereafter
sisshiki1969
0
380
Running Optcarrot (faster) on my own Ruby.
sisshiki1969
1
280
仮想マシンにおけるスタックの管理
sisshiki1969
0
230
Rustでゴミ集め
sisshiki1969
1
360
RustでつくるRubyのFiber
sisshiki1969
0
310
Shinjuku.rs#15 Rustでつくるx86アセンブラ
sisshiki1969
0
1.7k
Other Decks in Programming
See All in Programming
Unity6.3 AudioUpdate
cova8bitdots
0
130
文字コードの話
qnighy
44
17k
社内規程RAGの精度を73.3% → 100%に改善した話
oharu121
13
8.1k
OTP を自動で入力する裏技
megabitsenmzq
0
110
Go 1.26でのsliceのメモリアロケーション最適化 / Go 1.26 リリースパーティ #go126party
mazrean
1
400
GoのDB アクセスにおける 「型安全」と「柔軟性」の両立 - Bob という選択肢
tak848
0
110
コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions
handlename
0
200
RAGでハマりがちな"Excelの罠"を、データの構造化で突破する
harumiweb
9
2.9k
AI Assistants for Your Angular Solutions
manfredsteyer
PRO
0
140
Cyrius ーLinux非依存にコンテナをネイティブ実行する専用OSー
n4mlz
0
150
AIコードレビューの導入・運用と AI駆動開発における「AI4QA」の取り組みについて
hagevvashi
0
490
Claude Codeログ基盤の構築
giginet
PRO
7
3.3k
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
390
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
280
The Spectacular Lies of Maps
axbom
PRO
1
620
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Building the Perfect Custom Keyboard
takai
2
710
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
88
Skip the Path - Find Your Career Trail
mkilby
1
80
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Optimising Largest Contentful Paint
csswizardry
37
3.6k
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/