Bug 221316 - Optimize PointerCaptureController::elementWasRemoved()
Summary: Optimize PointerCaptureController::elementWasRemoved()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Simon Fraser (smfr)
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-02-02 21:27 PST by Simon Fraser (smfr)
Modified: 2021-02-03 10:45 PST (History)
4 users (show)

See Also:


Attachments
Patch (8.39 KB, patch)
2021-02-02 21:29 PST, Simon Fraser (smfr)
rniwa: review+
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Fraser (smfr) 2021-02-02 21:27:55 PST
Optimize PointerCaptureController::elementWasRemoved()
Comment 1 Simon Fraser (smfr) 2021-02-02 21:29:17 PST
Created attachment 419102 [details]
Patch
Comment 2 Ryosuke Niwa 2021-02-02 22:02:50 PST
Comment on attachment 419102 [details]
Patch

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

> Source/WebCore/page/PointerCaptureController.cpp:178
> +void PointerCaptureController::updateHaveAnyCapturingElement()

Do we need to eagerly update this or can we compute it lazily?
e.g. use Optional<bool> for m_haveAnyCapturingElement
and then haveAnyCapturingElement() inlined like haveAnyCapturingElement() { return m_haveAnyCapturingElement ? *m_haveAnyCapturingElement : haveAnyCapturingElementSlowCase();  }

> Source/WebCore/page/PointerCaptureController.cpp:180
> +    auto haveAnyCapturingElement = [&] {

Do we really need to use lambda here?
I find that setting m_haveAnyCapturingElement = false and breaking when the condition is hit would be easier to read.
Alternatively, can we just use anyOf in Algorithms.h so that:
m_haveAnyCapturingElement = WTF::anyOf(m_activePointerIdsToCapturingData.values(), [&] { ~ })

> Source/WebCore/page/PointerCaptureController.cpp:183
> +            if (capturingData.pendingTargetOverride || capturingData.targetOverride

Can we add a helper function on CapturingData like CapturingData::hasCapturingElement()?
Comment 3 Simon Fraser (smfr) 2021-02-03 10:07:48 PST
(In reply to Ryosuke Niwa from comment #2)
> Comment on attachment 419102 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=419102&action=review
> 
> > Source/WebCore/page/PointerCaptureController.cpp:178
> > +void PointerCaptureController::updateHaveAnyCapturingElement()
> 
> Do we need to eagerly update this or can we compute it lazily?
> e.g. use Optional<bool> for m_haveAnyCapturingElement
> and then haveAnyCapturingElement() inlined like haveAnyCapturingElement() {
> return m_haveAnyCapturingElement ? *m_haveAnyCapturingElement :
> haveAnyCapturingElementSlowCase();  }

I think it's better to do the work eagerly in the functions that start/stop capture, since the no-capture case is massively more common than the capturing case.

> 
> > Source/WebCore/page/PointerCaptureController.cpp:180
> > +    auto haveAnyCapturingElement = [&] {
> 
> Do we really need to use lambda here?
> I find that setting m_haveAnyCapturingElement = false and breaking when the
> condition is hit would be easier to read.
> Alternatively, can we just use anyOf in Algorithms.h so that:
> m_haveAnyCapturingElement =
> WTF::anyOf(m_activePointerIdsToCapturingData.values(), [&] { ~ })

I like the lambda. but I can change it.

> > Source/WebCore/page/PointerCaptureController.cpp:183
> > +            if (capturingData.pendingTargetOverride || capturingData.targetOverride
> 
> Can we add a helper function on CapturingData like
> CapturingData::hasCapturingElement()?

Will do.
Comment 4 Ryosuke Niwa 2021-02-03 10:31:15 PST
(In reply to Simon Fraser (smfr) from comment #3)
> (In reply to Ryosuke Niwa from comment #2)
> > Comment on attachment 419102 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=419102&action=review
> > 
> > > Source/WebCore/page/PointerCaptureController.cpp:178
> > > +void PointerCaptureController::updateHaveAnyCapturingElement()
> > 
> > Do we need to eagerly update this or can we compute it lazily?
> > e.g. use Optional<bool> for m_haveAnyCapturingElement
> > and then haveAnyCapturingElement() inlined like haveAnyCapturingElement() {
> > return m_haveAnyCapturingElement ? *m_haveAnyCapturingElement :
> > haveAnyCapturingElementSlowCase();  }
> 
> I think it's better to do the work eagerly in the functions that start/stop
> capture, since the no-capture case is massively more common than the
> capturing case.

Ok.

> > > Source/WebCore/page/PointerCaptureController.cpp:180
> > > +    auto haveAnyCapturingElement = [&] {
> > 
> > Do we really need to use lambda here?
> > I find that setting m_haveAnyCapturingElement = false and breaking when the
> > condition is hit would be easier to read.
> > Alternatively, can we just use anyOf in Algorithms.h so that:
> > m_haveAnyCapturingElement =
> > WTF::anyOf(m_activePointerIdsToCapturingData.values(), [&] { ~ })
> 
> I like the lambda. but I can change it.

Please use anyOf then.
Comment 5 Simon Fraser (smfr) 2021-02-03 10:44:53 PST
https://trac.webkit.org/changeset/272331/webkit
Comment 6 Radar WebKit Bug Importer 2021-02-03 10:45:18 PST
<rdar://problem/73939380>