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.
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
src: add Realm document in the src README.md #47932
src: add Realm document in the src README.md #47932
Changes from 2 commits
f0da57c
136cf14
a907870
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Should they actually share timers? I think the timer callbacks are tied to specific contexts too? Though I guess the event loop could be shared.
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.
Yeah, it would actually be very helpful to spell out what properties are being shared between different
Realm
s for the sameEnvironment
and which not. I've seen a bunch of PRs that move properties from theEnvironment
to the individualRealm
s, but it's not really clear where the line is and whether we're not essentially just introducing the ability to have multipleEnvironment
s similar to #47855.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.
Thanks for pointing this out! I've added a list of examples that can be shared across realms with an
Environment
.It is still yet to be done to share the async hook info between the realms -- it is necessary to link the async continuation between realm boundaries for AsyncLocalStorage to propagate correctly. This is essential to allow JS object access between multiple execution "environments" on the same thread.
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.
I’m not really sure that this answers the question. How is the end state of
Realm
going to be different from whatEnvironment
is (or used to be beforeRealm
s were introduced)?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 difference between the end state of the
Realm
and theEnvironment
would be:Environment
is associated with anIsolate
and provides the per-isolate hooks and APIs, and per-thread states, for instance, inspector agents, profilers, and APIs likeRequestInterrupt()
andcan_call_into_js()
.Realm
is associated with aContext
and consists of a global object and can be extended as a principal realm or a synthetic realm. EachEnvironment
has a single principal realm as its entry.As realms share the
Environment
instance, we don't have to create inspector IO threads, or profiler connections for each realm. The async local storage needs to be propagated across async boundaries in anotherRealm
of anEnvironment
too.Additionally, a
Realm
must be able to be repetitively created on the sameIsolate
and weakly referenced to properly support the ECMAScriptShadowRealm
API.As a conclusion, it is necessary to split the
Realm
andEnvironment
to distinguish per-isolate states and per-context states.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.
You’re describing
IsolateData
here, though.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.
Yes, it's true that
IsolateData
is also associated with anIsolate
. However, as documented,IsolateData
acts like a string table and contains information (e.g. startup snapshot data) about the isolate. It has its distinct properties compared to anEnvironment
.Compared to
IsolateData
,Environment
at the end state contains the necessary handles (bootstrapped with the principal realm) to propagate events across realm boundaries, for instance, propagating async local storages and promise rejection events fromShadowRealm
.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.
I think the current state we have is:
What we've been trying to do is to move per-isolate data in Environment to IsolateData and per-context data to Realm, it's happening but it's really not there yet.
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.
@addaleax do you think your question has been answered?