Repository navigation
Settle async WebAssembly on Apple JavaScriptCore and scope JSC wasm exclusions to Linux - #2068
Conversation
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
4 open issues
Switching fromexcludedJavaScriptEngines: [\"JavaScriptCore\"]toexcludedPlatforms: [\"Unix\"]… · New With a ~infinite timeout (1.0e10) and no explicit wake/stop on cancellation, the worker thread may… · New The Apple/JSC allow-list only includesmacOSandiOS, but the repo documentation lists… · NewTestUtils.getPlatformName()is called twice here. Store it in a local variable (similar to other… · New
What changed in this PR
Updates Apple JavaScriptCore AppRuntime threading so deferred engine work (notably async WebAssembly compile/instantiate) can complete, and refines validation test exclusions by introducing a platform-based exclusion field.
Changes:
- Add an Apple-specific CFRunLoop-based dispatch loop to allow JavaScriptCore deferred work to run and wake it when dispatching tasks.
- Enable async WebAssembly unit tests on Apple JSC and skip the blocking_tick hook-based test on Apple where the hook won’t fire.
- Add
excludedPlatformssupport in the Playground validation runner/config and expose platform name viaTestUtils.getPlatformName().
| File | Description |
|---|---|
| Plugins/TestUtils/Source/TestUtils.h | Exposes getPlatformName() to JS via N-API. |
| Plugins/TestUtils/Source/TestUtils.cpp | Implements GetPlatformName() from BABYLON_NATIVE_PLATFORM. |
| Plugins/TestUtils/CMakeLists.txt | Defines BABYLON_NATIVE_PLATFORM for TestUtils compilation. |
| Dependencies/JsRuntimeHost/Core/AppRuntime/Source/AppRuntime.cpp | Runs dispatcher via CFRunLoopSource on Apple and wakes the run loop on dispatch. |
| Dependencies/JsRuntimeHost/Tests/UnitTests/Source/Tests.AppRuntime.cpp | Skips the queue hook portion on Apple where the hook won’t execute. |
| Dependencies/JsRuntimeHost/Tests/UnitTests/Source/Scripts/tests.webAssembly.ts | Enables async Wasm tests on Apple JSC (macOS/iOS) in addition to V8. |
| Apps/Playground/Shared/CommandLine.cpp | Updates --include-excluded help text to include excludedPlatforms. |
| Apps/Playground/Scripts/validation_native.js | Adds excludedPlatforms filtering based on platform name. |
| Apps/Playground/Scripts/config.json | Changes prior JSC-wide exclusions to platform-based exclusions (Unix). |
| .github/instructions/babylon-native-debugging.instructions.md | Documents the new excludedPlatforms config field. |
Review effort: Lite
matthargett
left a comment
There was a problem hiding this comment.
The run-loop source design looks sound to me: event-driven, no polling, and I could not find a lost wake-up on shutdown. We carry a cruder version of this in a fork (a zero-timeout run-loop poll after each task) and will drop it in favour of this one, since a completion no longer has to wait for an unrelated dispatch.
One note on verification. It was done on macOS, where JavaScriptCore has a JIT. On device iOS and visionOS it does not, and the unit test skips silently when WebAssembly is undefined, so the iOS entry in the allow-list would pass even if wasm were unavailable there. If anyone has an iOS device result for the SPZ scenes, it would be worth adding to the description.
17470c6 to
8a55505
Compare
|
Good point. The PR description now says that iOS and visionOS were not verified on device and that the async WebAssembly test skips silently there without a JIT. |
ba2f397 to
ab45fcf
Compare
ab45fcf to
4bb2649
Compare
…bAssembly settles JavaScriptCore completes async WebAssembly compilation/instantiation by posting to the JS thread's CFRunLoop. The dispatch loop blocked in dispatcher.blocking_tick and never ran the run loop, so WebAssembly.instantiate/compile promises never settled (SPZ decoder, Manifold CSG2, etc. hung). On Apple, run the dispatcher from a CFRunLoopSource and wake the run loop when work is appended. Enable the async WebAssembly unit tests on Apple JSC and skip the blocking_tick hook test there. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5a2ca4f4-15a2-4ad1-8a64-9dad061e773d
Add an excludedPlatforms test config field (matched against BABYLON_NATIVE_PLATFORM via TestUtils.getPlatformName) and use it for the 18 tests previously excluded on all JavaScriptCore builds; they pass on Apple JSC now that async WebAssembly settles, and remain excluded on Linux JSC. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5a2ca4f4-15a2-4ad1-8a64-9dad061e773d
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7b64bf64-2ec3-499d-bf8a-c8cc0b066e4f
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7b64bf64-2ec3-499d-bf8a-c8cc0b066e4f
jsc-android is built without WebAssembly, so the SPZ loader falls back to ReadableStream (not provided by Babylon Native) and CSG2 cannot load Manifold. Android V8 passes all 18 tests, so allow excludedPlatforms entries of the form "Platform/Engine" and exclude "Android/JavaScriptCore" instead of all of Android. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8bd57bfd-bbb3-4e86-8a17-9a44fb995d0f
Add a per-engine AppRuntime::RunDispatchLoop hook. Every engine except JavaScriptCore keeps the blocking dispatcher loop; JavaScriptCore on Apple runs the thread's CFRunLoop, woken through a run loop source registered as the dispatch waker. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8bd57bfd-bbb3-4e86-8a17-9a44fb995d0f
4bb2649 to
e300e5f
Compare



Summary
JavaScriptCore finishes async WebAssembly compilation and instantiation by posting work to the JS thread's CFRunLoop. The Apple dispatch loop blocked in
dispatcher.blocking_tickand never ran the run loop. As a result,WebAssembly.instantiateandWebAssembly.compilepromises never settled, and anything that uses them hung (the SPZ decoder, Manifold CSG2, and so on).AppRuntime::RunDispatchLoophook. JavaScriptCore on Apple runs the thread's CFRunLoop, with the dispatcher driven by a CFRunLoopSource thatDispatchsignals. Every other engine, and JavaScriptCore on Linux, keeps the existing blocking dispatcher loop. The async WebAssembly unit tests are enabled on Apple JSC. The blocking_tick hook test is skipped there.excludedPlatformstest field, matched againstBABYLON_NATIVE_PLATFORMthroughTestUtils.getPlatformName. The 18 tests that were excluded on every JavaScriptCore build now pass on Apple JSC, so they are excluded only on Linux JSC.Side effect: JSC timers now fire on the JS thread
Running the JS thread's CFRunLoop also lets JavaScriptCore's other run-loop timers for the VM fire, not just the wasm completion. This includes the Eden and Full GC activity callbacks and the IncrementalSweeper, which sweeps in slices of up to about 10 ms and reschedules while blocks remain. These timers could not fire on this thread before.
So in every Apple JavaScriptCore app, not only wasm users, timer-driven collection and sweeping now run between dispatched tasks, and so do the Node-API finalizers they trigger. That should be a net win, because native resources are released sooner. A sweep slice can delay the next dispatched task, though, so frame time on older iPhones (A12/A13) is worth checking. This is based on WebKit's main branch; the system JavaScriptCore on a given OS version may differ.
Verification
WebAssemblyis undefined. So the iOS and visionOS entries in the allow-list are unconfirmed until someone runs the SPZ scenes on a device.