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
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
プロダクトだけじゃない、社内プロセスにおける自動化・省力化ノススメ
kakehashi
PRO
1
3.7k
SRE Lounge Hiroshimaへの招待
grimoh
0
640
CIで使うClaude
iwatatomoya
0
250
SRE本の知られざる名シーン / The Hidden Gems of Google SRE Book
nari_ex
1
380
公式ドキュメントの歩き方etc
coco_se
0
100
SRE依存からの脱却 運用を開 発チームへ移す、 フルサイ クル開 発体制の実践
joooee0000
0
2.7k
AICoEでAIネイティブ組織への進化
yukiogawa
0
170
最適な自走を最小限の支援で — M&Aで拡大する組織で少人数SREが挑んだ1年 / SRE NEXT 2026
genda
0
1.1k
あなたの『Site』はどこですか? — xREという考え方
miyamu
0
1.2k
GuardrailからGovernanceへ~AIエージェント運用の次の課題~
sbspsy
2
270
Empower GenAI with Agile - あなたのアジャイルが生成AIのバフになる仕組み
hageyahhoo
1
180
タスクの複雑さでモデルを選ぶ ── Thompson Samplingで動かす“トークン/コスト最適化
satohy0323
0
330
Featured
See All Featured
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
290
Speed Design
sergeychernyshev
33
1.9k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
1k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.4k
Marketing to machines
jonoalderson
1
5.6k
Design in an AI World
tapps
1
260
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Ethics towards AI in product and experience design
skipperchong
2
330
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
600
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
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