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

[DRAFT] [WIP] python isolate pool #2936

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

danlapid
Copy link
Contributor

No description provided.

@danlapid danlapid changed the title [WIP] python isolate pool [DRAFT] [WIP] python isolate pool Oct 16, 2024
] + glob(
[
"internal/*.ts",
"internal/topLevelEntropy/*.ts",
# The pool directory is only needed by typescript, it shouldn't be used at runtime.
"internal/pool/*.ts",
# "internal/pool/*.ts",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should run tsc --noEmit on this directory to make sure that our types are correct. Probably alongside the esbuild command, since esbuild by itself ignores types.

Comment on lines +3 to +13
struct EmscriptenSetup {
code @0 :Text;
pyodideAsmWasm @1 :Data;
pythonStdlibZip @2 :Data;
}

const emscriptenSetup :EmscriptenSetup = (
code = embed "emscriptenSetup.js",
pyodideAsmWasm = embed "pyodide.asm.wasm",
pythonStdlibZip = embed "python_stdlib.zip",
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to put this and pyodide.capnp together into the same capnproto.bin file so we don't have to upload/download two separate things.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The benefit of uploading two separate things is they are cached separately.
If we suspect this to change less often than the latter we'll get a big performance improvement.
This is a huge package (>10MB) while the other package is tiny.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then in order to get the performance improvement we'll need to make extra tooling to keep track of when the big package hasn't actually changed. If we try to do it manually we'll probably mess up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how that's different tooling to what we have now for the regular package

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I suppose if we upload separately, we can get that tooling working later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is either we always update both at the same time and then there is no caching benefit to separating them, or we need to somehow know when the bigger bundle hasn't changed.

@danlapid danlapid force-pushed the dlapid/python-pools2 branch 2 times, most recently from ed5d5c6 to 61c4df7 Compare October 17, 2024 11:05
@danlapid danlapid force-pushed the dlapid/python-pools2 branch 6 times, most recently from 7609106 to b3d8a00 Compare October 17, 2024 23:17
@@ -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;
Copy link
Contributor Author

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

@@ -93,15 +96,19 @@ wd_cc_library(
name = "pyodide",
srcs = [
"pyodide/pyodide.c++",
"pyodide/setup-emscripten.c++",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll want to merge this file into pyodide.c++

Comment on lines +23 to +30
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();
}
KJ_ASSERT(promise.state() == jsg::PromiseState::FULFILLED);
return promise.result();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. So this is asserting that each promise will be resolved in one trip around the event loop or... something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  /**
   * Runs the default MicrotaskQueue until it gets empty and perform other
   * microtask checkpoint steps, such as calling ClearKeptObjects. Asserts that
   * the MicrotasksPolicy is not kScoped. Any exceptions thrown by microtask
   * callbacks are swallowed.
   */

So it's not one trip around the event loop but rather, until we're completely done processing any events.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But only events that are microtasks not the main event loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you believe we are running here that does not count as a microtask?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't expect network IO to work if that's the question

Copy link
Contributor

@hoodmane hoodmane Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about compiling/instantiating webassembly? I didn't think that would be microtasks either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it works so I guess it is 😁

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good enough for me =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants