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
The state of Swift for WebAssembly in 2022
Search
Yuta Saito
September 12, 2022
Technology
16k
7
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
The state of Swift for WebAssembly in 2022
https://fortee.jp/iosdc-japan-2022/proposal/fa87f700-1483-456b-9b28-ba7c119cfa69
Yuta Saito
September 12, 2022
More Decks by Yuta Saito
See All by Yuta Saito
Swift at Scale: Where Performance Really Comes From
kateinoigakukun
0
210
The Evolution of the CRuby Build System
kateinoigakukun
3
1.1k
Running Swift on WebAssembly Platforms
kateinoigakukun
0
230
What you can do with Ruby on WebAssembly
kateinoigakukun
1
1.9k
RubyGems on ruby.wasm
kateinoigakukun
1
6.1k
Building a Smaller App Binary
kateinoigakukun
2
700
The new linker in Xcode 15
kateinoigakukun
4
4.4k
Optimizing your Swift code
kateinoigakukun
0
2.6k
Ruby & WebAssembly Introduction
kateinoigakukun
0
3.1k
Other Decks in Technology
See All in Technology
脱金融のフューチャー・デザイン / Future Design Beyond Finance
ks91
PRO
0
150
AI時代の開発生産性は、個人技からチーム設計へ
moongift
PRO
2
200
実装だけじゃない! CCA-F取得エンジニアが教えるClaude Code開発プロセス活用術
diggymo
2
660
あなたの『Site』はどこですか? — xREという考え方
miyamu
0
1.2k
穢れた技術選定について
watany
3
350
タスクの複雑さでモデルを選ぶ ── Thompson Samplingで動かす“トークン/コスト最適化
satohy0323
0
310
環境凍結という Toil を倒す -セルフサービス型 Ephemeral テスト環境の 設計と実践
shirouz
1
2.3k
LLMやAIエージェントをソフトウェアに組み込むプラクティス
shibuiwilliam
1
360
Mastraエージェント、どのクラウドにデプロイする?
minorun365
PRO
2
180
DMM.com 購入改善推進チーム におけるCodeRabbitを用いた レビューフロー改善の一例
ysknsid25
2
620
アカウントが増えてからでは遅い? ~ マルチアカウント統制の勘所 ~
kenichinakamura
0
220
事業価値を⽣み出すSREへ SREが担うべき意思決定の5層
kenta_hi
2
3.5k
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
Thoughts on Productivity
jonyablonski
76
5.2k
Test your architecture with Archunit
thirion
1
2.3k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.6k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.4k
Fireside Chat
paigeccino
42
4k
Are puppies a ranking factor?
jonoalderson
1
3.7k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.1k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
180
Ethics towards AI in product and experience design
skipperchong
2
330
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
460
sira's awesome portfolio website redesign presentation
elsirapls
0
300
Transcript
The state of Swift for WebAssembly in 2022 iOSDC 2022
@kateinoigakukun 1
About Me • @kateinoigakukun • Working at GoodNotes • SwiftWasm
ͷϝϯςφ • ৽ถ Swift / CRuby / LLVM ίϛολ • Love Swift ! 2
About this talk 1. Ϟνϕʔγϣϯ 2. SwiftWasm ͷϢʔεέʔε & σϞ
3. աڈ2ͷਐḿ 4. Future Work 3
Ϟνϕʔγϣϯ 4
Swiftͷ͖ͳͱ͜Ζ • ίϯύΠϧ͕௨Εେମಈ͘ • ਖ਼͍͠ίʔυΛ؆୯ʹॻͨ͘ΊͷIDEࢧԉ • ॊೈͳܕγεςϜ • ܕࢦ •
ConcurrencyͰਅՁΛൃش 5
SwiftͰΓ͍ͨ͜ͱ Run Swift anywhere • WebϒϥβͰಈ͘Swift • AndroidͰಈ͘Swift • ΫϥυϓϥοτϑΥʔϜͰಈ͘Swift
• SwiftͰॻ͚ΔϢʔβϓϥάΠϯ (e.g. VSCode Extension) 6
WebAssembly is a game changer A binary instruction format for
a stack-based machine Designed to be • Portable • Size- and Load-time efficient • Secure by Sandbox 7
WebAssemblyͷ࣮ߦϑϩʔ 8
SwiftWasm Project https://swiftwasm.org SwiftͷWebAssemblyରԠΛਐΊΔϓϩδΣΫτ • ίϯύΠϥΛͯ͠ύονΛૹͬͨΓɺ • WebAssembly͚ͷπʔϧνΣΠϯΛͨ͠Γɺ • JavaScriptKitͳͲͷपลϥΠϒϥϦͷ։ൃ
9
Demo: Run Swift on browser 10
11
12
ϓϩμΫγϣϯͰͷSwiftWasmͷϢʔεέʔε • GoodNotes1 • Note-taking app • Web Viewer for
sharing • Luminal2 • Python notebook on browser 2 https://getluminal.com/ 1 https://www.goodnotes.com/ 13
GoodNotesͷϨϯμϥ͕Web Ͱಈ͍ͯΔ༷ࢠ 14
WebAssembly is not only for Web 15
WebAssembly is not only for Web • αϯυϘοΫεʹΑΔ҆શੑɺϙʔλϒϧͳΞʔΩςΫνϟɺ ଟݴޠαϙʔτଞͷͰخ͍͠ •
ServerlessϓϥοτϑΥʔϜ • ϓϥάΠϯγεςϜ • and more… 16
WASI (WebAssembly System Interface) WebҎ֎ͰWasmΛಈ͔ͨ͢Ίͷඪ४γεςϜίʔϧن 17
https://hacks.mozilla.org/2019/03/standardizing-wasi-a-webassembly-system-interface/ 18
https://hacks.mozilla.org/2019/03/standardizing-wasi-a-webassembly-system-interface/ 19
WASI compatible things Platforms • Node.js / Deno / Wasmtime
• Fastly Compute@Edge • Cloudflare Workers • VSCode Extensions • Fluent Bit • Etc… Languages • C / C++ • Rust • Swift • Ruby • Etc… 20
Wasmಈ͔͢ڥίϯύΠϥخ͍͠ • ಈ͔͢ଆ: WebAssemblyϥϯλΠϜ͑͋͞Εɺ༷ʑͳݴޠΛ αϙʔτ͢Δ͜ͱ͕Ͱ͖Δ • ίϯύΠϥଆ: WebAssemblyʹίϯύΠϧͰ͖Εɺ༷ʑͳ ڥͰಈ͔ͤΔ 21
Demo: Swift CLI on WebAssembly 22
23
Web Ҏ֎ͷSwiftWasmͷϢʔεέʔε • Fastly Compute@Edge3 • Serverless platform based on
WebAssembly • Enarx4 • WebAssembly + Confidential Computing on TEE (Trusted Execution Environment) 4 https://enarx.dev/docs/webassembly/swift 3 https://www.fastly.com/jp/blog/introducing-serverless-swift-building-on-compute-edge-with-andrew-barba 24
Demo: Swift at Compute@Edge 25
26
For more info https://swift.cloud/blog/deploy-server-side-swift-to-fastly 27
ٕज़తͳਐḿ (2020~2022) • Relative PointerαϙʔτΛWasmʹՃ • 70Ҏ্ͷύονΛΞοϓετϦʔϜʹϚʔδ • Swift ConcurrencyʹରԠ
• Tokamak Fiber Renderer • μWASI 28
Relative Pointer SwiftͰΘΕ͍ͯΔϙΠϯλදݱͷςΫχοΫ • 64bitڥͰ32bitʹऩ·Δ • → όΠφϦαΠζخ͍͠ • Ґஔಠཱ
• → ʢେࡶʹݴ͏ͱʣ ΞϓϦىಈ͕ͯ͘خ͠ 29
Relative Pointer • Wasmͷ༷ͰදݱͰ͖ͳ͔ͬͨ template<typename BasePtrTy, typename Offset> uintptr_t applyRelativeOffset(BasePtrTy
*basePtr, Offset offset) { #ifdef __wasm__ // WebAssembly: hack: disable relative pointers return (uintptr_t)(intptr_t)offset; #endif auto base = reinterpret_cast<uintptr_t>(basePtr); auto extendOffset = (uintptr_t)(intptr_t)offset; return base + extendOffset; } 30
Relative Pointer ϋοΫਏ͍ • ίϯύΠϥͱϥϯλΠϜ྆ํʹେྔͷมߋ͕ඞཁ • ΞοϓετϦʔϜͰ৽͘͠Relative Pointerͷ༻͕૿͑Δͨͼ ʹέΞ͕ඞཁ 31
WasmʹRelative PointerαϙʔτΛՃ • WasmଆʹRelative Pointer ʹඞཁͳػೳΛఏҊ&࣮ 32
WebAssemblyͷͨΊʹSwiftΛ͢ 33
WebAssemblyͷͨΊʹSwiftΛ͢ SwiftͷͨΊʹWebAssemblyΛ͢ 34
ϋοΫ͕ফͤͯϋοϐʔ 35
Upstreaming patches • 44 patches for apple/swift • 16 patches
for apple/swift-corelibs-foundation • 14 patches for apple/swift-package-manager • 4 patches for LLVM They are made by only 2 people! 36
Swift Concurrency on Wasm JavaScriptKit provides a global executor implementation
based on JS event-loop import JavaScriptEventLoop import JavaScriptKit JavaScriptEventLoop.installGlobalExecutor() func printZen() async throws { let fetch = JSObject.global.fetch.function! let response = try await JSPromise(fetch("https://api.github.com/zen").object!)!.value let text = try await JSPromise(response.text().object!)!.value print(text) } 37
Tokamak Fiber Renderer • React 16Ҏ߱ͱಉͷΞϧΰϦζϜ • ਂ͘ωετͨ͠ViewͰελοΫΦʔόʔϑϩʔ͕ى͖ͳ͍ • ͜Ε·ͰͷStack
Reconciler30 viewsͷωετͰ ελοΫΦʔόʔϑϩʔ͍ͯͨ͠ • Fiber ReconcilerͰ700·ͰOK https://github.com/TokamakUI/Tokamak/pull/471 38
μWASI (swiftwasm/uwasi) • ܰྔWASI࣮ for ϒϥβ & Node.js • ैདྷͷ3rd-partyͷ࣮େ͖͗ͨ͢…
(65.6 KB) • େͷػೳͬͯͳ͔ͬͨ • SwiftWasmͰ৽͍͠ϞϊΛఏڙ: • Minimal: 3 KB • All features enabled: 6 KB https://github.com/swiftwasm/uwasi 39
Help wanted! • ·ͩ·ͩΔ͜ͱࢁ • ଟछଟ༷ͳқ/ϨΠϠ • ॿ͚͍ͯͩ͘͞ λεΫͷྖҬ 40
Future Work • KeyPathݺͼग़͠نΛSIL্ʹ੍ఆ • LLVM LTOʹΑΔίʔυݮΛnon-AppleϓϥοτϑΥʔϜʹҠ ২ • LLVMʹllvm.linker.usedΛՃͯ͠ɺϦϯΫ࣌GCΛ༗ޮԽ
• Web APIϕʔεͷFoundationNetworkingޓ࣮ • ܕ͖ͷJS <-> SwiftϒϦοδίʔυੜث 41
GoodNotes is hiring! https://www.goodnotes.com/careers • Senior Software Engineer, Cross Platform
(Swift, Wasm) • Senior Software Engineer, iOS • etc... 42
Thank you :) 43