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
190
The Evolution of the CRuby Build System
kateinoigakukun
3
1.1k
Running Swift on WebAssembly Platforms
kateinoigakukun
0
220
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
3k
Other Decks in Technology
See All in Technology
ACE-Step-1.5で見る 音楽生成AIのしくみと“破綻だけ直す”Retake機能の開発【zennfes spring 2026 登壇資料】
personabb
1
540
Kubernetesにおける学習基盤とLLMOpsの概要
ry
1
320
サイバーエージェントにおけるAI推進戦略と変革への取り組み
shotatsuge
0
130
AI-DLCを “そのまま導入しなかった”話 ~組織に合わせてアジャストした 私たちの実践共有~
hiroramos4
PRO
0
210
PostgreSQL 19 新機能概要 OSC Hokkaido 2026
nori_shinoda
0
140
不要なレビューをAIにまかせて AIコーディングの環境改善を加速した
shoota
1
230
新しいUbuntu/GNOMEが使いたいからXからWaylandへ移行頑張ってるの巻 2026-06-20
nobutomurata
0
150
Android の公式 Skill / Android skills
yanzm
0
160
自宅LLMの話
jacopen
1
650
2026 TECHFRESH 畢業分享會 - 開發日常大解密!從領域驅動到企業級上線
line_developers_tw
PRO
0
1.3k
白金鉱業Meetup_Vol.24_「AIエージェントは分けるほど良い」は本当か? / Is it true that “the more you divide AI agents, the better”?
brainpadpr
1
410
「勝手に広まる」人気 AI エージェントを爆速で作ろう!(AWS Summit Japan 2026講演資料)
minorun365
PRO
8
2k
Featured
See All Featured
The SEO identity crisis: Don't let AI make you average
varn
0
490
エンジニアに許された特別な時間の終わり
watany
107
250k
Practical Orchestrator
shlominoach
191
11k
From π to Pie charts
rasagy
0
210
My Coaching Mixtape
mlcsv
0
150
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
310
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
71
40k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
530
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.1k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
750
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
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