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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
Claude Codeをどのように キャッチアップしているか
oikon48
13
8.6k
【2026年版】 ベクトル検索とEmbedding最前線
mocobeta
16
4.4k
2026TECHFRESH畢業分享會 - Lightning Talk - 打造精準高效的 MCP 設計模式與測試實務
line_developers_tw
PRO
0
1.3k
[AWS Summit Japan 2026]迷っているあなたへ_小さな一歩が、やがて自分を助けてくれる
sh_fk2
1
160
生成 AI 実践ガイド (概略版) AIガバナンス編
asei
0
120
20260619 私の日常業務での生成 AI 活用
masaruogura
1
230
AI-DLCを “そのまま導入しなかった”話 ~組織に合わせてアジャストした 私たちの実践共有~
hiroramos4
PRO
0
210
新しいUbuntu/GNOMEが使いたいからXからWaylandへ移行頑張ってるの巻 2026-06-20
nobutomurata
0
150
あなたの知らないPDFのアクセシビリティ
lycorptech_jp
PRO
0
220
Bucharest Tech Week 2026 - Guardians of the Cloud-Native Galaxy
edeandrea
PRO
0
120
秘密度ラベル初心者が第1歩でつまづかないための「設計・運用」ポイント
seafay
PRO
0
210
AIAU_UMEMOGU_ninomiya_slide
ninomiya_ii
0
240
Featured
See All Featured
The SEO Collaboration Effect
kristinabergwall1
1
490
Done Done
chrislema
186
16k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
870
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
950
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Ethics towards AI in product and experience design
skipperchong
2
310
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Automating Front-end Workflow
addyosmani
1370
210k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
600
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