Bug 204219 - JS wrappers of scroll event targets can get prematurely collected by GC
Summary: JS wrappers of scroll event targets can get prematurely collected by GC
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Scrolling (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-11-14 23:02 PST by Ryosuke Niwa
Modified: 2019-11-15 15:05 PST (History)
11 users (show)

See Also:


Attachments
Fixes the bug (8.65 KB, patch)
2019-11-14 23:11 PST, Ryosuke Niwa
keith_miller: 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-14 23:02:22 PST
We don't keep JS wrappers of scroll event targets alive while it's waiting to be fired in the next rendering update.
This bug has always existed but it's worse after https://trac.webkit.org/r252205 because it delays the firing of the event.
Comment 1 Ryosuke Niwa 2019-11-14 23:11:55 PST
Created attachment 383603 [details]
Fixes the bug
Comment 2 Ryosuke Niwa 2019-11-14 23:12:28 PST
Note: I've checked the world leaks with run-webkit-tests --debug --world-leaks fast/scrolling.
Comment 3 Radar WebKit Bug Importer 2019-11-14 23:13:54 PST
<rdar://problem/57218306>
Comment 4 Keith Miller 2019-11-15 09:16:36 PST
Comment on attachment 383603 [details]
Fixes the bug

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

> Source/WebCore/ChangeLog:11
> +        r252205 because there is more of a time delay between an element is scrolled in RenderLayer sense
> +        and when the corresponding scroll event is fired on the element.

this sentence is weird. maybe "because there is a greater delay between when an element is scrolled in the RenderLayer and when the corresponding scroll event is fired on the element" is clearer?

> Source/WebCore/dom/Document.cpp:373
> +// Defined here to avoid including GCReachableRef.h in Document.h
> +struct Document::PendingScrollEventTargetList {
> +    WTF_MAKE_FAST_ALLOCATED;
> +
> +public:
> +    Vector<GCReachableRef<ContainerNode>> targets;
> +};

I thought you said there was a pending activity class? Can we just use that instead?
Comment 5 Ryosuke Niwa 2019-11-15 09:39:36 PST
(In reply to Keith Miller from comment #4)
> Comment on attachment 383603 [details]
> Fixes the bug
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=383603&action=review
> 
> > Source/WebCore/ChangeLog:11
> > +        r252205 because there is more of a time delay between an element is scrolled in RenderLayer sense
> > +        and when the corresponding scroll event is fired on the element.
> 
> this sentence is weird. maybe "because there is a greater delay between when
> an element is scrolled in the RenderLayer and when the corresponding scroll
> event is fired on the element" is clearer?

Sure.

> > Source/WebCore/dom/Document.cpp:373
> > +// Defined here to avoid including GCReachableRef.h in Document.h
> > +struct Document::PendingScrollEventTargetList {
> > +    WTF_MAKE_FAST_ALLOCATED;
> > +
> > +public:
> > +    Vector<GCReachableRef<ContainerNode>> targets;
> > +};
> 
> I thought you said there was a pending activity class? Can we just use that
> instead?

No, we can't make every ContainerNode an active DOM object because ContainerNode is a very common object in DOM.
Comment 6 Keith Miller 2019-11-15 10:20:53 PST
Comment on attachment 383603 [details]
Fixes the bug

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

r=me.

>>> Source/WebCore/dom/Document.cpp:373
>>> +};
>> 
>> I thought you said there was a pending activity class? Can we just use that instead?
> 
> No, we can't make every ContainerNode an active DOM object because ContainerNode is a very common object in DOM.

Oh, I thought the system worked with any node, presumably via GCReachableRef.

> Source/WebCore/dom/Document.cpp:4021
> +    if (targets.findMatching([&target] (auto& entry) { return entry.ptr() == &target; }) != notFound)

Why not just [&]? It's all gonna get inlined anyway.
Comment 7 Ryosuke Niwa 2019-11-15 12:07:36 PST
(In reply to Keith Miller from comment #6)
> Comment on attachment 383603 [details]
> Fixes the bug
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=383603&action=review
> 
> r=me.
> 
> >>> Source/WebCore/dom/Document.cpp:373
> >>> +};
> >> 
> >> I thought you said there was a pending activity class? Can we just use that instead?
> > 
> > No, we can't make every ContainerNode an active DOM object because ContainerNode is a very common object in DOM.
> 
> Oh, I thought the system worked with any node, presumably via GCReachableRef.

No, pending activity is for active DOM objects. We use GCReachableRef when a Node needs to be kept alive by something other than Node itself (if it is, then we make that particular node an active DOM object).

> > Source/WebCore/dom/Document.cpp:4021
> > +    if (targets.findMatching([&target] (auto& entry) { return entry.ptr() == &target; }) != notFound)
> 
> Why not just [&]? It's all gonna get inlined anyway.

Sure.
Comment 8 Ryosuke Niwa 2019-11-15 15:05:53 PST
Committed r252504: <https://trac.webkit.org/changeset/252504>