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
Node.js x WebAssembly
Search
Yosuke Furukawa
PRO
March 31, 2017
Programming
4
1.1k
Node.js x WebAssembly
Node学園24時限目で発表した Node.js と WebAssembly のデモですー。
Yosuke Furukawa
PRO
March 31, 2017
Tweet
Share
More Decks by Yosuke Furukawa
See All by Yosuke Furukawa
Welcome JSConf.jp 2024
yosuke_furukawa
PRO
1
3.4k
tc39 x jsconf.jp Panel Discussion 2024
yosuke_furukawa
PRO
0
170
Removing Corepack
yosuke_furukawa
PRO
9
1.3k
JavaScript Runtime とはなにか
yosuke_furukawa
PRO
15
2.5k
Strip Types と Storage
yosuke_furukawa
PRO
4
350
Module Harmony について
yosuke_furukawa
PRO
3
1.6k
LTのやり方
yosuke_furukawa
PRO
16
2.2k
AppRouter Panel Talk
yosuke_furukawa
PRO
3
730
Node.js v22 で変わること
yosuke_furukawa
PRO
13
5.5k
Other Decks in Programming
See All in Programming
103 Early Hints
sugi_0000
1
270
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
350
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
230
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
7
1.6k
Внедряем бюджетирование, или Как сделать хорошо?
lamodatech
0
750
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
1.1k
Kaigi on Railsに初参加したら、その日にLT登壇が決定した件について
tama50505
0
120
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
160
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
180
バグを見つけた?それAppleに直してもらおう!
uetyo
0
190
Jakarta EE meets AI
ivargrimstad
0
310
CloudflareStack でRAGに入門
asahiiwm
0
130
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
1
120
Site-Speed That Sticks
csswizardry
2
190
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Designing for Performance
lara
604
68k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.6k
Typedesign – Prime Four
hannesfritz
40
2.4k
Code Reviewing Like a Champion
maltzj
521
39k
Transcript
Node x WebAssembly 2017, Mar, 31th @ NodeֶԂ 24࣌ݶ in
FiNC
Twitter: @yosuke_furukawa Github: yosuke-furukawa
WebAssembly
WebAssembly Goals • ϙʔλϒϧ͔ͭϩʔυޮ͕ྑ͍όΠφϦϑΥʔϚο τΛ࡞Δ͜ͱ • ϋʔυΣΞ(mobile, IoT ؚΉ)ͷೳྗΛϑϧʹ׆͔ ͯ͠nativeͷͱಉͷ࣮ߦ࣌ؒͰܭࢉ͢Δ͜ͱ
• طଘͷϓϥοτϑΥʔϜ(web)ͱͷੑΛߴ͘͠ ͯɺ౷߹͘͢͢͠Δ͜ͱ http://webassembly.org/docs/high-level-goals/
WebAssembly UseCases
WebAssembly UseCase (1) • ωΠςΟϒϞδϡʔϧΛϒϥβͰಡΈࠐΉ
WebAssembly UseCase (1) • ωΠςΟϒϞδϡʔϧΛϒϥβͰಡΈࠐΉ
WebAssembly UseCase (2) • Game
WebAssembly Use Cases • BrowserϢʔεέʔε • CC++(Rust)Ͱॻ͔ΕͨωΠςΟϒϞ δϡʔϧΛϒϥβ͔ΒಡΈࠐΊΔΑ͏ʹ ͢Δ •
Game / ը૾ೝࣝ / ҉߸Խ / ѹॖ֦ு etc etc http://webassembly.org/docs/use-cases/
WebAssembly Use Cases • BrowerҎ֎ͷϢʔεέʔε • Server Side application •
Native Apps on mobile devices http://webassembly.org/docs/use-cases/
WebAssembly͕Ͳ͏ΘΕΔ ͜ͱΛఆ͢Δ͔ʁ • શମͷίʔυϕʔεΛWebAssemblyԽ͞ΕΔ ͜ͱΛظ • ͱ͍͑ɺWeb UIͷϨΠϠHTML/JSͷ·· • ͻͱ·ͣϝΠϯλʔήοτCC++Ͱॻ͔Ε
͍ͯΔطଘίʔυΛJSͰݺΔΑ͏ʹ͢Δ http://webassembly.org/docs/use-cases/
Node.js x Native Modules
Node.js x Native Module • NAN Ͱ࡞ͬͯϞδϡʔϧΛϥοϓ͢Δ • node-ffi Ͱ
FFI ݺͼग़͠ʹ͢Δ • emscriptenͰasm.jsʹ͢Δ • emscriptenͰwasmʹ͢Δ
Node.js x Native Module • NAN Ͱ࡞ͬͯϞδϡʔϧΛϥοϓ͢Δ
Node.js x Native Module • NAN Ͱ࡞ͬͯϞδϡʔϧΛϥοϓ͢Δ • V8ͷAPIόʔδϣϯมΘΔͱେମյΕΔ •
ͦΕʹґଘ͍ͯ͠ΔNative Moduleେମյ ΕΔ • ͦͷAPIΛநԽͯ͠ٵऩ͢Δͷ͕NAN
Node.js x Native Module • NAN Ͱ࡞ͬͯϞδϡʔϧΛϥοϓ͢Δ • ࣗ༝͕ߴ͍ •
ͦͷΘΓbindingͷͨΊͷίʔυΛ৭ʑ֤ ඞཁ͕͋Δ
Node.js x Native Module • node-ffi Ͱ FFI ݺͼग़͠ʹ͢Δ
Node.js x Native Module • node-ffi Ͱ FFI ݺͼग़͠ʹ͢Δ •
Foreign Function Interface (ݴޠ͕༻ҙͯ͠ ͘Ε͍ͯΔಛ༗ͷ֎෦ݺͼग़͠ػೳ) • libffi Λ library ͱͯ͠ϩʔυ͍ͯ͠ΔͷͰC C++ͷίʔυͰ͋Εಈ͘
Node.js x Native Module • node-ffi Ͱ FFI ݺͼग़͠ʹ͢Δ •
؆୯ • ͨͩ͠ɺ֎෦ݺͼग़͠ʹͳΔͨΊFFI͍
Node.js x Native Module • emscriptenͰasm.jsʹ͢Δ
Node.js x Native Module • emscriptenͰasm.jsʹ͢Δ • emscriptenͷఏڙ͢ΔίϯύΠϥͰasm.jsԽ͢ Δ •
asm.jsMozilla͕ఏএɺChrome/Edgeα ϙʔτ༧ఆͰwasmͷpolyfillͱͯ͠ಈ͘Մೳ ੑ͋Γ
Node.js x Native Module • emscriptenͰasm.jsʹ͢Δ • ؆୯ʢ͚ͩͲɺҙ֎ͱಈ͔ͳ͔ͬͨΓ͢Δʣ • શͯJavaScriptʹͳΓɺϑΝΠϧαΠζ͕ڊେʹ
ͳΔ • ࣮ࡍNode.jsͷཪͷv8asm.jsΛϑϧαϙʔτ ͯ͠ͳ͔ͬͨΓͰ͋·Γ͘ͳ͍
Node.js x Native Module • emscriptenͰwasmʹ͢Δ (NEW!!)
Node.js x Native Module • emscriptenͰwasmʹ͢Δ • asm.jsͱಉ͡؆୯͞ • v8ͷ࠷৽ͩͱwasmରԠࡁΈͳͷͰී௨ʹಈ͘
• ·ͩ·ͩʢJSJIT͕ޮ͘ͷͰ୯७ͳܭ ࢉͩͱ JS > WebAssemblyʹͳΔ͜ͱ͋Δʣ
͞Βʹ࠷ۙͰ
Node.js ʹ stable module ABI ͷ PR͕Ճ͞ΕͯΔ • https://github.com/nodejs/node/pull/11975
Node.js ʹ stable module ABI ͷ PR͕Ճ͞ΕͯΔ • ͳͷͰɺ5ͭ: stable
module ABIͰ࡞Δ • ͍উखతʹNANͱҰॹ • ৽͍͠APIͳͷͰதʢ·ͩࢼͯ͠ͳ͍ʣ
ͳͷͰ
Node.js x Native Module • NAN Ͱ࡞ͬͯϞδϡʔϧΛϥοϓ͢Δ • node-ffi Ͱ
FFI ݺͼग़͠ʹ͢Δ • emscriptenͰasm.jsʹ͢Δ • emscriptenͰwasmʹ͢Δ (new!!! node v8 Ͱ༗ޮʹ) • stable module ABI ʹ͢Δ (new!!! node v8 Ͱ༗ޮʹ)
WebAssembly DEMO
butteraugly DEMO
Node.js x WebAssembly • ࢥ৭ʑ͋ΕͲ໘ന͍ • WebAssemblyʹͨ͠΄͏͕ϒϥβͰ Ͱ͖Δ͜ͱ͕ଟ͘ͳΔͱࢥΘΕΔ • ࠓ·ͩΈΜͳ৭ʑτϥΠͯ͠νΣοΫͯ͠
Δ࠷த