Notable changes this month: JavaScriptKit 0.64.0 optimizations make creating, passing and releasing JSObjects 30-50% faster; WasmKit 0.5.0 added wasm2wat and the wide-arithmetic proposal; ElementaryUI 0.9.0 added ForEach keyed by id and server-side rendering; uWASI gained an OPFS filesystem backend for browser storage.
Many thanks to @felipepiovezan, k0michi, @kabiroberai, @kateinoigakukun, @kebo, @krodak, @Logan_Shire, @mozharovsky, @silver-ben, @sliemeobn, @Tony_Parker, and Vithanco for contributions!
Forum Discussions
- ElementaryUI now faster than React and Angular in benchmark: the latest development snapshot of
js-framework-benchmarkranks ElementaryUI, its only Swift entry, ahead of React, Angular and Yew. - SwiftUIWeb: Bringing SwiftUI to the browser with Embedded Swift and WebAssembly: SwiftUIWeb runs SwiftUI code in the browser, with Embedded Swift compiled to Wasm in a Web Worker and a JavaScript layer applying updates to the DOM, and Apple's Food Truck sample now builds for iPhone, iPad and the browser from the same sources.
- ActorRPC: distributed actors over HTTP, now playing in a browser near you: an ElementaryUI app built with Embedded Swift calls a
distributed actoron AWS Lambda.
Swift Toolchain
swiftc on development snapshots gained experimental support for loading a macro compiled to a statically linked Wasm binary, meaning consumers of the macro would not need to depend on SwiftSyntax. LLDB gained Wasm global, symbol and frame-ordering fixes.
- Add experimental support for Wasm macros, loaded with
-load-plugin-executable Foo.wasm#Fooswift#73031; - Run the
wasip1-threadstests under WasmKit, build the Embedded standard library for thewasip1-threadstriple, and initialize a globalMutexstatically on WASI swift#92238; - Document the Wasm ABI for Swift async functions, async context is always in local 0 swift#93554, and preserve the async-context attribute on
swift_task_switchandswift_asyncLet_finish, where declarations lowered to inconsistent signatures with Wasm tail calls swift#93062; - LLDB: scope Wasm global reads to a module instance llvm-project#14800, create data symbols from the Wasm export section llvm-project#14845, read Wasm globals through a frame of the stub's own thread llvm-project#14866, number the Wasm virtual registers llvm-project#14871, and order frames by their call frame addresses, Wasm frames included llvm-project#15106;
- Fix an LLVM assertion on a function with a stack protector that ends in a Wasm tail call llvm-project#15074.
JavaScriptKit
JavaScriptKit 0.63.0 fixed BridgeJS glue for thrown errors and JSValue ownership and shrank --wasi-runtime uwasi bundles, 0.63.1 fixed two typed array copy bugs, and 0.64.0 stopped deduplicating JSObject references in the object heap. Creating, passing and releasing JSObjects is now 30-50% faster, and the cost no longer grows with the number of live objects. As a trade-off, JSObject is no longer Hashable, and JSObject.== calls into JavaScript to compare with ===.
- BridgeJS: check thrown errors before lifting return values, so an exported
throws(JSException)function that returns aJSObjectthrows the Swift error in JavaScript instead of aReferenceError#824; - BridgeJS: diagnose
asyncand throwing@JSstruct initializers #825; - BridgeJS: fix
JSValuereference ownership across the bridge, which crashed when returning aJSValuethat Swift created #826; - PackageToJS: import only the UWASI features Swift needs, which shrinks a
--wasi-runtime uwasibundle from 8.8 KB to 4.8 KB, minified and gzipped #827; - Runtime: copy only the view's window in
swjs_load_typed_array, instead of the whole backingArrayBuffer#810; - BridgeJS: normalize the pointer in
swift_js_push_typed_array, which read the wrong range once memory grew past 2 GiB #828; - Runtime: stop deduplicating
JSObjectreferences in the object heap #835.
WasmKit
0.5.0 adds the wasm2wat function and CLI for disassembling .wasm modules, support for the wide-arithmetic proposal, guard-page memory on iOS and Android, WASI calls that trap on out-of-bounds guest pointers, and faster execution through new instruction fusions.
- Add the
wasm2watfunction and CLI #305; - Read the opcode after a prefix byte as LEB128, so overlong encodings such as
fc 80 00decode #510, and support the wide-arithmetic proposal #511; - Return after a tail call to a host function, instead of running the code that follows it #509;
- WASI: trap on an out-of-bounds guest pointer, which used to stop the host process #524, and transfer short when
ioveclengths add up past 4 GiB #525; - Enable guard-page shared memory and WASI Threads on iOS #513, and guard-page memory bounds checking on Android #527;
- Reclaim unused constant-pool reservations before spilling literals #516;
- Keep small internal calls off the native stack #517;
- Fuse instruction sequences common in compiled code #529, and xor-shift mixing sequences #518;
- Fix the
WITOverlayGeneratoroutput for Swift 6 mode #533.
ElementaryUI
ElementaryUI 0.8.1 sped up attribute patching. 0.9.0 added ForEach keyed by any Hashable id:, basic server-side rendering of views with .render(), and faster list updates and reactive state changes; it deprecates key: and .key() in favor of id: and .id(), and ForEach now requires a RandomAccessCollection. 0.9.1 added @ViewEquatableIgnored, and 0.9.2 fixed the bezier timing curves and added SVG transforms.
- Faster attribute patching #144;
- Basic support for SSR/SSG rendering of views #145;
- Persistent reactive listeners, so a function view without reactive reads no longer allocates a listener #146, with an allocation-free listener callback for schedulable nodes #148 and cheaper listener fan-in #147;
- Key
ForEachby anyHashableid, with per-row tracking #149, and make row tracking and updates cheaper #150; - Switch the examples, benchmarks and integration tests to uWASI, for a JavaScript bundle about 6.7 kB smaller #155;
- Replace the
_Reconcilableunmount with a per-slot unmount registry #156; - Store state and environment values in
UniqueAny#157, and useassertinstead ofpreconditionon hot typed-access checks #161; - Make the
CustomAnimationdefaults public #158; - Implement
@ViewEquatableIgnored#163; - Unify modifier and environment dependency tracking #162;
- Fix bezier timing curves to match CSS
cubic-bezier()#164; - Skip style updates queued for a modifier that has since unmounted, which tripped a precondition when a fade was removed without animation in the same tick as an animated sibling #167;
- Add
rotationEffectandscaleEffectfor SVG #126.
uWASI
On main, an OPFS filesystem backend lets a browser guest keep its files across page reloads and worker restarts.
- Add an OPFS filesystem backend #35.
Other Projects
- Foundation: fix the
wasm32-unknown-emscriptenbuild ofFoundationEssentialsby importingEmscriptenLibcswift-foundation#2359, stopcreateDirectory(atPath:withIntermediateDirectories:)recursing past/, which never ended on WASI without a preopen covering/swift-foundation#2409, and build more ofFoundationEssentialsandFoundationInternationalizationfor Embedded Swift on Wasm swift-foundation#2368, including XML property list parsing swift-foundation#2456; - Add WASI support to
swift-format, which now builds with its tests forwasm32-unknown-wasip1andwasm32-unknown-wasip1-threadsswift-format#1319; - Pass
--wasi-threadsto WasmKit forwasip1-threadsin the Swift SDK generator swift-sdk-generator#284; vite-plugin-swift-wasm: preload the wasm module in HTML entries vite-plugin-swift-wasm#9, and addjsoptions withwasiRuntimevite-plugin-swift-wasm#10.
Thank you for reading, and please feel free to add any comments or suggestions if we missed anything!
If you'd like to catch up with changes from previous months, here's a list of recent updates: