-
-
Notifications
You must be signed in to change notification settings - Fork 83
feat: introduce v8 locker in our codebase #549
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DESCRIPTION: vfs uses binary search internally, so it must be properly sorted. However, it is inappropriate to use IndexMap::(...)::collect() and expect the elements to be sorted.
DESCRIPTION: When the main worker's script relays an HTTP request to the user worker, it may already be in a retired state.
laktek
approved these changes
Jun 18, 2025
Given the nature of the change, let's merge and conduct some additional stress testing within internal staging environment. |
2 tasks
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Feature, Enhancement
Description
Introducing the v8 Locker API to our code base.
Deno prefers to have only one runtime in a single thread, but it is possible to have multiple runtimes in a single thread as long as thread-local variables are managed properly.
edge-runtime may need to manage hundreds (or even thousands) of runtimes in a single process, so instead of matching threads and runtimes one-to-one, we chose a model where a tokio thread can have multiple runtimes.
While this model avoided the overhead of spawning extra threads by having only a small number of threads, it also meant that there was only a fixed number of runtimes that any particular thread could process at any given time, so the slower any runtime processed, the slower the other runtimes tied to the same thread would process.
To mitigate this issue, we can temporarily separate the runtime that is reached particular stage, which is expected to take up most of the lifecycle, such as the bootstrapping stage, from the tokio thread and process it in a separate thread pool so that the processing time of the tokio thread does not slow down.
The problem is that in order to enable the runtime to move between multiple threads, we need the Locker API from v8.
Deno had previously attempted to introduce this API into their library, but ultimately gave up.
We ended up forking their library and introducing the API they had given up.
What's changed (or fixed)
WorkerAlreadyRetired
has been introduced. If you try to reuse a retired worker (i.e., call worker.fetch), the error will be thrown. (Please refer to the updated example/main/index.ts)Closes FUNC-183, FUNC-215