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

Expose `JavaScriptEventLoop.queueMicrotask` and `.setTimeout` #214

Closed kateinoigakukun closed 1 year ago

kateinoigakukun commented 1 year ago

This allows users to have more flexibility to customize. For example, this allows inserting operations before/after single job execution loop. e.g. It's useful to enable React batch rendering per job execution loop by ReactDOM.unstable_batchedUpdates.

let original = JavaScriptEventLoop.shared.queueMicrotask
JavaScriptEventLoop.shared.queueMicrotask = (job) => {
  ReactDOM.unstable_batchedUpdates(() => {
    original(job)
  })
}
github-actions[bot] commented 1 year ago

Time Change: -141ms (0%)

Total Time: 18,740ms

Test name Duration Change
Serialization/JavaScript function call through Wasm import 23ms +1ms (5%) 🔍
Serialization/JavaScript function call through Wasm import with int 20ms -2ms (11%) 👏
View Unchanged | Test name | Duration | Change | | :--- | :---: | :---: | | Serialization/JavaScript function call from Swift | 200ms | +2ms (0%) | | Serialization/Swift Int to JavaScript with assignment | 448ms | -7ms (1%) | | Serialization/Swift Int to JavaScript with call | 1,384ms | -12ms (0%) | | Serialization/JavaScript Number to Swift Int | 480ms | +3ms (0%) | | Serialization/Swift String to JavaScript with assignment | 508ms | -4ms (0%) | | Serialization/Swift String to JavaScript with call | 1,493ms | -10ms (0%) | | Serialization/JavaScript String to Swift String | 5,976ms | +30ms (0%) | | Object heap/Increment and decrement RC | 8,191ms | -140ms (1%) |
View Baselines | Test name | Duration | | :--- | :---: | | Serialization/Call JavaScript function directly | 2ms | | Serialization/Assign JavaScript number directly | 3ms | | Serialization/Call with JavaScript number directly | 5ms | | Serialization/Write JavaScript string directly | 4ms | | Serialization/Call with JavaScript string directly | 4ms |