swiftwasm / JavaScriptKit

Swift framework to interact with JavaScript through WebAssembly.
https://swiftpackageindex.com/swiftwasm/JavaScriptKit/main/documentation/javascriptkit
MIT License
664 stars 44 forks source link

Allocate JavaScriptEventLoop per thread in multi-threaded environment #255

Closed kateinoigakukun closed 2 months ago

kateinoigakukun commented 2 months ago

This change makes JavaScriptEventLoop to be allocated per thread in multi-threaded environment. This is necessary to ensure that a job enqueued in one thread is executed in the same thread because JSObject managed by a worker can only be accessed in the same thread.

Currently, swift_task_enqueueMainExecutor_hook continues enqueuing jobs to the current thread event loop. It should eventually enqueue to the main thread event loop even if it's enqueued from worker threads.

github-actions[bot] commented 2 months ago

Time Change: +234ms (2%)

Total Time: 9,543ms

Test name Duration Change
Serialization/JavaScript function call through Wasm import 22ms +2ms (7%) 🔍
Serialization/JavaScript function call from Swift 101ms +5ms (5%) 🔍
Serialization/JavaScript Number to Swift Int 313ms +17ms (5%) 🔍
View Unchanged | Test name | Duration | Change | | :--- | :---: | :---: | | Serialization/JavaScript function call through Wasm import with int | 17ms | -1ms | | Serialization/Swift Int to JavaScript with assignment | 334ms | +1ms (0%) | | Serialization/Swift Int to JavaScript with call | 971ms | +34ms (3%) | | Serialization/Swift String to JavaScript with assignment | 410ms | +15ms (3%) | | Serialization/Swift String to JavaScript with call | 1,010ms | +14ms (1%) | | Serialization/JavaScript String to Swift String | 3,707ms | +78ms (2%) | | Object heap/Increment and decrement RC | 2,644ms | +68ms (2%) |
View Baselines | Test name | Duration | | :--- | :---: | | Serialization/Call JavaScript function directly | 3ms | | Serialization/Assign JavaScript number directly | 2ms | | Serialization/Call with JavaScript number directly | 4ms | | Serialization/Write JavaScript string directly | 2ms | | Serialization/Call with JavaScript string directly | 3ms |