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
560
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
27
Improving my own Ruby thereafter
sisshiki1969
1
250
あなたとJIT, 今すぐアセンブ ル
sisshiki1969
1
1.1k
Improve my own Ruby
sisshiki1969
1
600
My own Ruby, thereafter
sisshiki1969
0
420
Running Optcarrot (faster) on my own Ruby.
sisshiki1969
1
330
仮想マシンにおけるスタックの管理
sisshiki1969
0
250
Rustでゴミ集め
sisshiki1969
1
390
RustでつくるRubyのFiber
sisshiki1969
0
330
Other Decks in Programming
See All in Programming
運用ダッシュボードの設計を誰も教えてくれないのだけどみなさんどうしてるんですか? - チームに監視するという文化を根付かせるための第一歩を踏みたい -
satoshi256kbyte
1
140
Hono + Inertia + React で LP を構築した話
oukayuka
2
150
AIに既存システムを理解させる技術 ~レガシーを見捨てないハーネスエンジニアリング入門~
ochtum
0
140
今さら聞けない .NET CLI
htkym
0
210
FastAPI の並行処理モデルを完全に理解する
hoto17296
8
2.8k
源内ハンズオン概要編
hideg
0
210
プロポーザルを書いてもらう
pvcresin
0
580
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
1.2k
Press start. Python's next generation.
willingc
PRO
2
110
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
710
[PyCon KR 2026] More Variants, More Diversity for AI Accelerators
achimnol
0
110
楽しそうなつよつよエンジニアと目が死んでる僕/A brilliant engineer having a blast, and dead-eyed me.
3l4l5
2
240
Featured
See All Featured
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
400
New Earth Scene 8
popppiees
3
2.5k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.1k
The Language of Interfaces
destraynor
162
27k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
580
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
950
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
240
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
Google's AI Overviews - The New Search
badams
0
1.1k
Mind Mapping
helmedeiros
PRO
1
330
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/