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

Do we need to mandate agents and event loops being 1:1? #2526

Closed
domenic opened this issue Apr 13, 2017 · 5 comments

Comments

2 participants
@domenic
Copy link
Member

commented Apr 13, 2017

As discussed in #2521 and related threads, we are working to define the concept of "agent" from the ES spec.

I think it's possible that agents and event loops might need to be 1:1 in a world that includes SharedArrayBuffers. I haven't worked through the argument in full yet, but I think SABs make it observable that, for example, implementations do not use a single event loop for every Window in the user agent. If they did that, there would be sequential consistency guaranteed between tasks enqueued in different agents. Previously the relative order of those tasks was unobservable, so even if the spec mandated such sequential consistency, it wasn't a true normative requirement. But now you can use SABs to observe the task ordering across different agents, and so you could observe that in fact every implementation uses one event loop per agent, not one big event loop for the entire browser.

I guess upon writing that out, we don't need to change the spec, since the spec already allows one event loop per agent. But the spec implies you could get away with one event loop per browser, and I think that is not true in practice... I dunno, I'm a bit twisted around as to whether this is a real problem.

@annevk

This comment has been minimized.

Copy link
Member

commented Apr 13, 2017

but I think SABs make it observable that, for example, implementations do not use a single event loop for every Window in the user agent

I don't see how. From a Window object a SharedArrayBuffer can only be shared with similar-origin Window objects (and dedicated workers, but that doesn't matter here as far as I can tell) and those are all inside the same Agent as well as inside the same Agent Cluster. Any non-similar-origin Window objects are in a different Agent Cluster and passing a SharedArrayBuffer to them would fail. So I don't see how you can observe the event loop.

(I made this point several times, though I can't find a reference right now so I'm posting it again.)

@annevk

This comment has been minimized.

Copy link
Member

commented Apr 13, 2017

The other point I made is that in implementations today they very much use the same event loop for some non-similar-origin Window objects, in particular cross-origin <iframe>s.

@domenic

This comment has been minimized.

Copy link
Member Author

commented Apr 13, 2017

From a Window object a SharedArrayBuffer can only be shared with similar-origin Window objects (and dedicated workers, but that doesn't matter here as far as I can tell) and those are all inside the same Agent as well as inside the same Agent Cluster.

You can postMessage to other agents within your agent cluster.

@annevk

This comment has been minimized.

Copy link
Member

commented Apr 13, 2017

Yes you can, but there will only be one Agent consisting of Window objects there. The other agents will only ever be dedicated workers.

@domenic

This comment has been minimized.

Copy link
Member Author

commented Apr 13, 2017

Right, OK, I forgot you couldn't postMessage SABs cross-origin-domain.

I think that kills this thread. I still have an intuition agents and event loops should be more related, but I can't base it on anything, so let me close this.

Thanks for walking me through things!!

@domenic domenic closed this Apr 13, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.