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
StarlingMonkeyを触ってみた話 - 2024冬
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
syumai
December 11, 2024
Programming
560
3
Share
StarlingMonkeyを触ってみた話 - 2024冬
新宿御苑.wasm #2024.12.11 の発表資料です
https://shinjukugyoen.connpass.com/event/338017/
syumai
December 11, 2024
More Decks by syumai
See All by syumai
『[入門] Cloudflare Workers』本はなぜ誕生したのか
syumai
0
300
tsgolintはいかにしてtypescript-goの非公開APIを呼び出しているのか
syumai
9
3k
知られているようで知られていない JavaScriptの仕様 4選
syumai
3
1.2k
CloudflareのSandbox SDKを試してみた
syumai
0
790
実践AIチャットボットUI実装入門
syumai
9
4.1k
ProxyによるWindow間RPC機構の構築
syumai
3
1.5k
CloudflareのChat Agent Starter Kitで簡単!AIチャットボット構築
syumai
2
1.2k
Go製CLIツールをnpmで配布するには
syumai
3
2k
MCPで実現できる、Webサービス利用体験について
syumai
7
3k
Other Decks in Programming
See All in Programming
20260514_its_the_context_window_stupid.pdf
heita
0
860
From Formal Specification to Property Based Test
ohbarye
0
2.4k
Are We Really Coding 10× Faster with AI?
kohzas
0
140
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
240
エラー処理の温故知新 / history of error handling technic
ryotanakaya
7
1.9k
認証統合から始めるフロントエンドの機能単位開発 — マイクロサービス思想の適用
koukimiura
0
100
AI時代のエンジニアリングの原則 / Engineering Principles in the AI Era
haru860
0
1.1k
Kingdom of the Machine
yui_knk
2
1.5k
Spec Driven Development | AI Summit Vilnius
danielsogl
PRO
1
150
ソースコード→AST→オペコード、の旅を覗いてみる
o0h
PRO
1
130
🦞OpenClaw works with AWS
licux
1
350
アクセシビリティ試験の"その後"を仕組み化する
yuuumiravy
1
200
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Deep Space Network (abreviated)
tonyrice
0
130
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
120
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
360
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.4k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.1k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
800
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
180
Building Adaptive Systems
keathley
44
3k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
920
Transcript
StarlingMonkey を触ってみた話 - 2024 冬 syumai 新宿御苑.wasm (2024/12/11)
自己紹介 syumai ECMAScript 仕様輪読会 / Asakusa.go 主催 株式会社ベースマキナで管理画面のSaaS を開発中 Go
でGraphQL サーバー (gqlgen) や TypeScript でフロント エンドを書いています Software Design 2023 年12 月号からCloudflare Workers の連載 をしてます Twitter ( 現𝕏): @__syumai Website: https://syum.ai
StarlingMonkey とは
StarlingMonkey とは Bytecode Alliance のOrganization 配下でメンテナンスされているSpiderMonkey のfork SpiderMonkey は言わずと知れた、Mozilla Firefox
のJS エンジン WebAssembly Component Model で使いやすくするための最適化が行われている
StarlingMonkey はどこで使われているのか? Fastly のjs-compute-runtime Fastly Compute はWasm を実行するランタイム JS を実行するには、JS
エンジンをWasm 化して組み込む必要がある ComponentizeJS JS のコードをWebAssembly Components として使えるように変換するツール StarlingMonkey をそのままWasm バイナリにバンドルする Fermyon のSpin JS SDK ComponentizeJS を組み込んだSDK なので、StarlingMonkey の利用は間接的 事情はFastly Compute に似ている Spin は、WebAssembly Component をデプロイできる基盤
StarlingMonkey の成り立ち ( 注) 完全に追っていた訳ではないので、断片的です! もともと、Fastly のjs-compute-runtime が内部で使用しているSpiderMonkey fork が
Bytecode Alliance 配下にあった 実はまだある: bytecodealliance/gecko-dev 別で、ComponentizeJS が独自にSpiderMonkey にpatch を当てていた ( 開発はほとんどFastly の@guybedford さんがやっている様子) → SpiderMonkey をWasm 化した上でアプリケーションに組み込むという同じ目的で、 複数のプロジェクトが独自に動いているという状況になった ここで、Fastly とFermyon のエンジニアが協働して、Bytecode Alliance 配下にWasm 最 適化を施したSpiderMonkey fork を置くようにした
Introducing our Next-Generation JavaScript SDK - Fermyon
Introducing our Next-Generation JavaScript SDK - Fermyon
StarlingMonkey を使う
StarlingMonkey のビルド README 通りに実行すればいいので簡単! https://github.com/bytecodealliance/StarlingMonkey cmake --build cmake-build-release (or debug)
でビルドすると、 starling- raw.wasm が得られる 生成されたディレクトリに入った componentize.sh を実行してWasm Component 化 されたStarlingMonkey が完成 cd cmake-build-release ./componentize.sh -o starling.wasm
ビルドしたStarlingMonkey の使用 wasmtime に突っ込んでJS の実行に使える WASI のHTTP のインタフェースを通じて実行する形式 $ wasmtime
-S http starling.wasm -e "console.log('hello world')" Log: hello world
StarlingMonkey を活用する
StarlingMonkey を活用する 自分の実力では、そのまま使うのは正直きつかった 生成されたStarlingMonkey のWasm Component に、cli とhttp のインタフェースし か実装されていない
JS 以外の言語から、 eval_JS みたいな関数呼び出し形式でJS を呼べたら便利そう だが、どうやったらこうできるかが想像できなかった http のインタフェースをうまく使ったらいける?
StarlingMonkey を活用する 参考: StarlingMonkey のWasm Component にjco を通した結果 (cli /
http がexport されている)
StarlingMonkey を活用する 結局ComponentizeJS を使うのが楽 JS のコードとStarlingMonkey を抱き合わせてWasm Component 化したものをあら ゆる言語上で簡単に動かせます
jco とComponentizeJS を使って作ったWasm Component をNode.js で動かすとこ ろまでは簡単にできました 見た感じ、ComponentizeJS にはStarlingMonkey にパッチを当ててるC++ のコード が結構含まれてそうな気配がしている(ちゃんと追えてない)
感想 C++ を読み書きできるようになりたい!
ご清聴ありがとうございました!