-
Notifications
You must be signed in to change notification settings - Fork 303
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
Workerd side of python isolate pool #2936
base: dlapid/refactor_limitenforcer_workerobserver
Are you sure you want to change the base?
Workerd side of python isolate pool #2936
Conversation
7609106
to
b3d8a00
Compare
@@ -68,4 +68,8 @@ interface Module { | |||
addRunDependency(x: string): void; | |||
removeRunDependency(x: string): void; | |||
noInitialRun: boolean; | |||
setUnsafeEval(mod: typeof import('internal:unsafe-eval').default): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type imports must be here instead of an import statement because we use this file as an "ambient" type declaration.
See https://stackoverflow.com/questions/39040108/import-class-in-definition-file-d-ts
1deb2c2
to
e4e608b
Compare
bc1543a
to
1a87fae
Compare
2e46939
to
05e7568
Compare
Removing from draft stage as this is pretty much the end state of this PR. |
@hoodmane this is a breaking change to the bundle, I'll need an explanation of how we can do that safely in a way that won't break backwards compatibility |
You should be able to:
Then when we roll it out, the bundle patch version changes at the same time as the C++ code. |
05ca004
to
ef18feb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, some small nits/questions, but otherwise LGTM.
KJ_IF_SOME(module, emscriptenModule) { | ||
return module.getHandle(js); | ||
} else { | ||
auto& runtime = KJ_ASSERT_NONNULL(workerd::Worker::Api::current().getEmscriptenRuntime()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The KJ_ASSERT_NONNULL
below makes sense, but what about this one? Is it guaranteed for the return of this function to never be kj::none? If so, can its type be changed to not return a kj::Maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it can be guaranteed that if we have a python worker this HAS to be instantiated before we call getModule.
If for some reason someone called SetupEmscripten.getModule without an emscripten runtime this should definitely fail and there's now way to recover from it.
That being said, for any isolate that isn't a python isolate emscriptenRuntime will always be a kj::none and SetupEmscripten.getModule will simply never be called.
jsg::JsValue resolvePromise(jsg::Lock& js, jsg::JsValue prom) { | ||
auto promise = KJ_ASSERT_NONNULL(prom.tryCast<jsg::JsPromise>()); | ||
if (promise.state() == jsg::PromiseState::PENDING) { | ||
js.runMicrotasks(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can doing this block the thread for too long and prevent other isolates from doing work?
I guess we will run this in its own thread, so this won't be an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously this logic would run in the global await that the loading of the pyodide bundle would block on. It's essentially the exact same logic just moved.
This means that we aren't blocking for any more time than we previously did but simply blocking at stage that's a bit earlier.
For workerd that doesn't matter at all.
For our internal use case it will maintain the original behaviour for any isolate that isn't part of the pool (yeah those still exist).
If the isolate is part of the pool then this will run in a separate thread and actually improve the current status.
b7fe651
to
cf2324b
Compare
Changes to typescript look good to me. |
9349b16
to
f5bc217
Compare
Move ownership of metrics and limitEnforcer to the api type. Currently ownership is shared even though the Isolate class encapsulates the api class. Moving complete ownership to the underlying api class allows the isolate class to be constructed in a different scope to the api class. This is useful for preinitialization of the api class before a request has come in. Add updateConfiguration function to jsg Isolates This can be used to update the given configuration at runtime. Note that while some jsg structs are lazily using the configuration, others can use it at construction and will have the original configuration value.
cf2324b
to
317e535
Compare
No description provided.