Skip to content

Make it explicit that "this" is available in parallel #11110

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

Closed
annevk opened this issue Mar 7, 2025 · 4 comments · Fixed by #11129
Closed

Make it explicit that "this" is available in parallel #11110

annevk opened this issue Mar 7, 2025 · 4 comments · Fixed by #11129

Comments

@annevk
Copy link
Member

annevk commented Mar 7, 2025

What is the issue with the HTML Standard?

Various other operations (such as method steps) can go in parallel at some point. In various places we rely on "this" being available (and thus kept alive). We should make this assumption explicit in the in parallel section.

@domfarolino
Copy link
Member

Yikes! Do we want this to be able to be relied on in parallel? Whenever I catch this being used in parallel, I find that this blurs the line between Window event loop and parallel contexts to the point of adding more confusion—people think they can do everything else that they can from a Window event loop, like resolve promises, or grab state that actually has to be synchronized correctly without thinking through it. I've also found that folks consider the lifetime of global-bound objects from parallel contexts even less than normal, which I think is bad, since when you go in parallel the lifetimes of things are now unbound.

I usually encourage people to make this explicit by closing over what they actually need from this (sometimes grabbing that object itself if necessary) and explicitly checking in on or its global before using it later. I'd love for us to converge on that model for global event loop 🤝 parallelism.

@annevk
Copy link
Member Author

annevk commented Mar 11, 2025

I mean that's what I did, but @domenic suggested I do the opposite.

I would personally also prefer that eventually we get more explicit about what kind of state can be shared.

@domfarolino
Copy link
Member

Ah, that surprises me. I don't think we should promote using this in parallel, but if @domenic has a compelling rationale I am all ears.

@domenic
Copy link
Member

domenic commented Mar 12, 2025

I don't feel too strongly. My rationale is that this cannot change what it points to, so saving it in a variable doesn't feel very useful.

But, your point that people should not generally access Web IDL objects in parallel is a good one. Similarly, your point about how bringing this in might cause people to start thinking other stuff is OK is compelling.

My main remaining complaint is that I find the pattern

1. Let global be this's relevant global object.
2. In parallel:
   1. ...
   2. Queue a global task on X task source using global to...

to be a bit annoyingly-verbose compared to

1. In parallel:
   1. ...
   2. Queue a global task on X task source using this's relevant global object to...

but I guess the better solution to that is to work on whatwg/webidl#135 (and in particular the sub-thread around in parallel behavior. (Where I tend to agree more with @jyasskin these days than I do with my 2017 self. I guess my 2021 proposal at whatwg/webidl#135 (comment) is the best current idea.)

So, I'm OK with saying that this must not be accessed in parallel.

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

Successfully merging a pull request may close this issue.

3 participants