Bug 204492 - There should be one MicrotaskQueue per EventLoop
Summary: There should be one MicrotaskQueue per EventLoop
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: InRadar
Depends on: 204978
Blocks: 204042
  Show dependency treegraph
 
Reported: 2019-11-21 22:49 PST by Ryosuke Niwa
Modified: 2019-12-08 15:27 PST (History)
14 users (show)

See Also:


Attachments
WIP (17.67 KB, patch)
2019-12-05 21:28 PST, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
WIP2 (17.87 KB, patch)
2019-12-05 22:51 PST, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Patch (24.64 KB, patch)
2019-12-06 16:42 PST, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
updated for trunk (25.72 KB, patch)
2019-12-07 18:51 PST, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
updated for trunk (25.77 KB, patch)
2019-12-07 19:07 PST, Ryosuke Niwa
koivisto: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2019-11-21 22:49:13 PST
HTML5 spec mandates that we should have one microtask queue per similar origin documents.
This leads to bugs like https://bugs.webkit.org/show_bug.cgi?id=199565.

In addition, MutationObserver's compound microtask queue must be per similar origin windows,
and Custom Element's backup queue must be per micro per similar origin windows.
Comment 1 Radar WebKit Bug Importer 2019-11-21 22:49:35 PST
<rdar://problem/57420645>
Comment 2 Ryosuke Niwa 2019-12-05 21:28:23 PST
Created attachment 384990 [details]
WIP
Comment 3 Ryosuke Niwa 2019-12-05 22:51:21 PST
Created attachment 384991 [details]
WIP2
Comment 4 Ryosuke Niwa 2019-12-06 16:42:59 PST
Created attachment 385059 [details]
Patch
Comment 5 Sam Weinig 2019-12-06 18:33:13 PST
Comment on attachment 385059 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=385059&action=review

> Source/WebCore/dom/CustomElementReactionQueue.h:48
> +class ElementQueue {

This name seems a little too generic now that it is not a nested class. Can we make more specific?
Comment 6 Ryosuke Niwa 2019-12-06 18:35:07 PST
(In reply to Sam Weinig from comment #5)
> Comment on attachment 385059 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=385059&action=review
> 
> > Source/WebCore/dom/CustomElementReactionQueue.h:48
> > +class ElementQueue {
> 
> This name seems a little too generic now that it is not a nested class. Can
> we make more specific?

That's what HTML5 spec uses:
https://html.spec.whatwg.org/multipage/custom-elements.html#element-queue

But we can rename it to CustomElementQueue if anything. Perhaps adding a spec URL there might help clarify the purpose of this class?
Comment 7 Ryosuke Niwa 2019-12-06 23:35:48 PST
Comment on attachment 385059 [details]
Patch

Ah, we have a bug in the way event loop is selected for unique origins.
Comment 8 Ryosuke Niwa 2019-12-07 16:54:07 PST
(In reply to Ryosuke Niwa from comment #6)
> (In reply to Sam Weinig from comment #5)
> > Comment on attachment 385059 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=385059&action=review
> > 
> > > Source/WebCore/dom/CustomElementReactionQueue.h:48
> > > +class ElementQueue {
> > 
> > This name seems a little too generic now that it is not a nested class. Can
> > we make more specific?
> 
> That's what HTML5 spec uses:
> https://html.spec.whatwg.org/multipage/custom-elements.html#element-queue
> 
> But we can rename it to CustomElementQueue if anything. Perhaps adding a
> spec URL there might help clarify the purpose of this class?

Added URL and rename end it to CustomElementQueue.
Comment 9 Ryosuke Niwa 2019-12-07 18:51:43 PST
Created attachment 385110 [details]
updated for trunk
Comment 10 Ryosuke Niwa 2019-12-07 19:07:19 PST
Created attachment 385112 [details]
updated for trunk
Comment 11 Antti Koivisto 2019-12-08 00:24:53 PST
Comment on attachment 385112 [details]
updated for trunk

View in context: https://bugs.webkit.org/attachment.cgi?id=385112&action=review

> LayoutTests/ChangeLog:1
> -2019-12-07  Ryosuke Niwa  <rniwa@webkit.org>
> +2019-12-08  Ryosuke Niwa  <rniwa@webkit.org>

Stray ChangeLog change.
Comment 12 Antti Koivisto 2019-12-08 00:32:43 PST
Comment on attachment 385112 [details]
updated for trunk

View in context: https://bugs.webkit.org/attachment.cgi?id=385112&action=review

> Source/WebCore/dom/WindowEventLoop.h:51
> +    Vector<GCReachableRef<HTMLSlotElement>>& signalSlotList() { return m_signalSlotList; }
> +    HashSet<RefPtr<MutationObserver>>& activeMutationObservers() { return m_activeObservers; }
> +    HashSet<RefPtr<MutationObserver>>& suspendedMutationObservers() { return m_suspendedObservers; }

It is bit sad these need to be exposed as public and mutable. I wonder this code could be factored so that more of the mutations would be internal to WindowEventLoop?
Comment 13 Ryosuke Niwa 2019-12-08 00:39:37 PST
(In reply to Antti Koivisto from comment #12)
> Comment on attachment 385112 [details]
> updated for trunk
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=385112&action=review
> 
> > Source/WebCore/dom/WindowEventLoop.h:51
> > +    Vector<GCReachableRef<HTMLSlotElement>>& signalSlotList() { return m_signalSlotList; }
> > +    HashSet<RefPtr<MutationObserver>>& activeMutationObservers() { return m_activeObservers; }
> > +    HashSet<RefPtr<MutationObserver>>& suspendedMutationObservers() { return m_suspendedObservers; }
> 
> It is bit sad these need to be exposed as public and mutable. I wonder this
> code could be factored so that more of the mutations would be internal to
> WindowEventLoop?

You mean the whole mutation observer notification code? If we did that, we’d have to make more of mutation observer code public. We rely on inlining, etc... so that’s not so great. I’ve also considered making WindowEventLoop supplementable or creating a new class like SimilarOrginWindowData or strict specific to mutation observers but they didn’t seem to make the encapsulation any more strict / cleaner :(
Comment 14 Ryosuke Niwa 2019-12-08 00:42:11 PST
I think we should probably go ahead with this simple approach for now, and think about a way to refactor it better once we’re done with the event loop work and Yusuke’s work to introduce JSC side optimization for microtasks is done. There are just too many moving pieces to come up with a clean abstraction at the moment.
Comment 15 Antti Koivisto 2019-12-08 05:50:14 PST
Yeah,it is fine. Was just wondering.
Comment 16 Ryosuke Niwa 2019-12-08 15:26:53 PST
Comment on attachment 385112 [details]
updated for trunk

View in context: https://bugs.webkit.org/attachment.cgi?id=385112&action=review

>> LayoutTests/ChangeLog:1
>> +2019-12-08  Ryosuke Niwa  <rniwa@webkit.org>
> 
> Stray ChangeLog change.

Fixed.
Comment 17 Ryosuke Niwa 2019-12-08 15:27:28 PST
Committed r253279: <https://trac.webkit.org/changeset/253279>