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

Add an option to newContext to disable memoization of global context … #2999

Merged
merged 1 commit into from
Oct 25, 2024

Conversation

danlapid
Copy link
Contributor

…template.

For Python Isolate Pools we want to instantiate emscripten in a separate context on isolate creation (before we have compatibility flags) and later after receiving the compatibility flags create a new context.
One blocker to this approach is all the templates that are instantiated in the first context are memoized.
This PR allows us to create a new context without memoizing the global context templates.
This feature is off by default and will be enabled in a future PR for python isolates only.

@danlapid danlapid force-pushed the dlapid/context_disable_memoize branch 2 times, most recently from 1afc837 to 8e026ba Compare October 24, 2024 23:43
@@ -527,14 +533,15 @@ template <typename TypeWrapper,
const char* methodName,
typename Method,
Method method,
bool isContext>
bool isContext,
bool memoize>
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking nit... really not a big fan of bool args like this. Much prefer enums for this type of case. Won't block on it tho

src/workerd/jsg/resource.h Outdated Show resolved Hide resolved
@danlapid danlapid marked this pull request as ready for review October 24, 2024 23:50
@danlapid danlapid requested review from a team as code owners October 24, 2024 23:50
@danlapid danlapid force-pushed the dlapid/context_disable_memoize branch from 8e026ba to d4d60d7 Compare October 25, 2024 00:00
@danlapid
Copy link
Contributor Author

@jasnell is this good to go?

Copy link
Collaborator

@dom96 dom96 left a comment

Choose a reason for hiding this comment

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

Changes LGTM assuming this is the cleanest way to achieve what we need. I don't have a lot of context on this code so will leave to someone else to approve.

Comment on lines +1463 to +1470
//
// When creating a new context the global context template will be memoized for future reuse in
// additional contexts. The global context can depend on `configuration`. For Python Isolate
// Pools we want to create a new context and initialize some code in it and later when a request
// arrives, edit the configuration and create a new context. To achieve this we create the first
// context with `memoize=false` to disable memoization of the global context created for the
// first context. Then we create a new context with `memoize=true` to enable memoization of the
// main context created after a request was received.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably a stupid question, but I wonder why we cannot overwrite the memoized context after it has been memoized?

Copy link
Contributor Author

@danlapid danlapid Oct 25, 2024

Choose a reason for hiding this comment

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

That would require the inverse of the same logic changing the code flow that existed before this change rather than adding a different code flow for our exceptional case.

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

LGTM but there's a merge conflict and let's be sure to run an internal CI job before merging to make sure there are no issues on the internal repo

…template.

For Python Isolate Pools we want to instantiate emscripten in a separate
context on isolate creation (before we have compatibility flags) and
later after receiving the compatibility flags create a new context.
One blocker to this approach is all the templates that are instantiated
in the first context are memoized. This PR allows us to create a new
context without memoizing the global context templates. This feature is
off by default and will be enabled in a future PR for python isolates
only.
@danlapid danlapid force-pushed the dlapid/context_disable_memoize branch from d4d60d7 to 57365ba Compare October 25, 2024 19:55
@danlapid danlapid merged commit 0b6df82 into main Oct 25, 2024
13 checks passed
@danlapid danlapid deleted the dlapid/context_disable_memoize branch October 25, 2024 20:33
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.

3 participants