Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allocate JavaScriptEventLoop per thread in multi-threaded environment #255

Merged
merged 6 commits into from
Jun 27, 2024

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Jun 27, 2024

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.

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.
Copy link

github-actions bot commented Jun 27, 2024

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

@kateinoigakukun kateinoigakukun force-pushed the yt/tls-eventloop branch 2 times, most recently from 18e42e9 to 8364fe1 Compare June 27, 2024 06:30
Swift 5.7 doesn't support short-circuit evaluation in `#if` conditions
@kateinoigakukun kateinoigakukun marked this pull request as ready for review June 27, 2024 06:59
@kateinoigakukun kateinoigakukun merged commit 0d39aa7 into main Jun 27, 2024
16 checks passed
@kateinoigakukun kateinoigakukun deleted the yt/tls-eventloop branch June 27, 2024 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant