Bug 204492

Summary: There should be one MicrotaskQueue per EventLoop
Product: WebKit Reporter: Ryosuke Niwa <rniwa>
Component: DOMAssignee: Ryosuke Niwa <rniwa>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, dbates, esprehn+autocc, ews-watchlist, ggaren, kangil.han, keith_miller, koivisto, mifenton, rniwa, sam, webkit-bug-importer, wenson_hsieh, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 204978    
Bug Blocks: 204042    
Attachments:
Description Flags
WIP
none
WIP2
none
Patch
none
updated for trunk
none
updated for trunk koivisto: review+

Ryosuke Niwa
Reported 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.
Attachments
WIP (17.67 KB, patch)
2019-12-05 21:28 PST, Ryosuke Niwa
no flags
WIP2 (17.87 KB, patch)
2019-12-05 22:51 PST, Ryosuke Niwa
no flags
Patch (24.64 KB, patch)
2019-12-06 16:42 PST, Ryosuke Niwa
no flags
updated for trunk (25.72 KB, patch)
2019-12-07 18:51 PST, Ryosuke Niwa
no flags
updated for trunk (25.77 KB, patch)
2019-12-07 19:07 PST, Ryosuke Niwa
koivisto: review+
Radar WebKit Bug Importer
Comment 1 2019-11-21 22:49:35 PST
Ryosuke Niwa
Comment 2 2019-12-05 21:28:23 PST
Ryosuke Niwa
Comment 3 2019-12-05 22:51:21 PST
Ryosuke Niwa
Comment 4 2019-12-06 16:42:59 PST
Sam Weinig
Comment 5 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?
Ryosuke Niwa
Comment 6 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?
Ryosuke Niwa
Comment 7 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.
Ryosuke Niwa
Comment 8 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.
Ryosuke Niwa
Comment 9 2019-12-07 18:51:43 PST
Created attachment 385110 [details] updated for trunk
Ryosuke Niwa
Comment 10 2019-12-07 19:07:19 PST
Created attachment 385112 [details] updated for trunk
Antti Koivisto
Comment 11 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.
Antti Koivisto
Comment 12 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?
Ryosuke Niwa
Comment 13 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 :(
Ryosuke Niwa
Comment 14 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.
Antti Koivisto
Comment 15 2019-12-08 05:50:14 PST
Yeah,it is fine. Was just wondering.
Ryosuke Niwa
Comment 16 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.
Ryosuke Niwa
Comment 17 2019-12-08 15:27:28 PST
Note You need to log in before you can comment on or make changes to this bug.