Bug 194073 - Hit testing functions optimizations
Summary: Hit testing functions optimizations
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Benjamin Poulain
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-01-30 20:39 PST by Benjamin Poulain
Modified: 2019-02-05 00:52 PST (History)
8 users (show)

See Also:


Attachments
Patch (7.72 KB, patch)
2019-01-30 20:42 PST, Benjamin Poulain
no flags Details | Formatted Diff | Diff
Patch (10.43 KB, patch)
2019-01-31 20:37 PST, Benjamin Poulain
no flags Details | Formatted Diff | Diff
Patch (21.24 KB, patch)
2019-02-01 18:44 PST, Benjamin Poulain
no flags Details | Formatted Diff | Diff
Patch (4.22 KB, patch)
2019-02-04 21:06 PST, Benjamin Poulain
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Poulain 2019-01-30 20:39:59 PST
<rdar://problem/47692312> Hit testing functions optimizations
Comment 1 Benjamin Poulain 2019-01-30 20:42:00 PST
Created attachment 360684 [details]
Patch
Comment 2 Benjamin Poulain 2019-01-30 20:42:02 PST
<rdar://problem/47692312>
Comment 3 Simon Fraser (smfr) 2019-01-31 13:58:11 PST
Comment on attachment 360684 [details]
Patch

Do any of these really make measurable perf improvements?
Comment 4 Benjamin Poulain 2019-01-31 15:58:44 PST
(In reply to Simon Fraser (smfr) from comment #3)
> Comment on attachment 360684 [details]
> Patch
> 
> Do any of these really make measurable perf improvements?

Oh yeah.

Maybe not on your machine but on older CPUs that hurts.
Comment 5 Tim Horton 2019-01-31 16:04:19 PST
Comment on attachment 360684 [details]
Patch

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

> Source/WTF/ChangeLog:4
> +        <rdar://problem/47692312> Hit testing functions optimizations
> +        https://bugs.webkit.org/show_bug.cgi?id=194073

This is usually:

Title
Bugzilla link
Radar link
Comment 6 Simon Fraser (smfr) 2019-01-31 16:07:00 PST
"webkit-patch upload" will format the changelog for you.
Comment 7 zalan 2019-01-31 16:08:29 PST
or prepare-ChangeLog -b 194073 if you prefer uploading patches manually.
Comment 8 Benjamin Poulain 2019-01-31 16:47:02 PST
(In reply to Tim Horton from comment #5)
> Comment on attachment 360684 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=360684&action=review
> 
> > Source/WTF/ChangeLog:4
> > +        <rdar://problem/47692312> Hit testing functions optimizations
> > +        https://bugs.webkit.org/show_bug.cgi?id=194073
> 
> This is usually:
> 
> Title
> Bugzilla link
> Radar link

I just use the radar title as bug title. What's the easiest way to create bugzilla bug from radars?
Comment 9 Tim Horton 2019-01-31 16:50:19 PST
(In reply to Benjamin Poulain from comment #8)
> (In reply to Tim Horton from comment #5)
> > Comment on attachment 360684 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=360684&action=review
> > 
> > > Source/WTF/ChangeLog:4
> > > +        <rdar://problem/47692312> Hit testing functions optimizations
> > > +        https://bugs.webkit.org/show_bug.cgi?id=194073
> > 
> > This is usually:
> > 
> > Title
> > Bugzilla link
> > Radar link
> 
> I just use the radar title as bug title. What's the easiest way to create
> bugzilla bug from radars?

webkit-patch will make a bugzilla bug for you when you're uploading your patch
Comment 10 Benjamin Poulain 2019-01-31 16:56:02 PST
(In reply to Tim Horton from comment #9)
> > I just use the radar title as bug title. What's the easiest way to create
> > bugzilla bug from radars?
> 
> webkit-patch will make a bugzilla bug for you when you're uploading your
> patch

What I always use.
Comment 11 Benjamin Poulain 2019-01-31 20:37:49 PST
Created attachment 360823 [details]
Patch
Comment 12 Benjamin Poulain 2019-01-31 20:40:02 PST
(In reply to Benjamin Poulain from comment #4)
> (In reply to Simon Fraser (smfr) from comment #3)
> > Comment on attachment 360684 [details]
> > Patch
> > 
> > Do any of these really make measurable perf improvements?
> 
> Oh yeah.
> 
> Maybe not on your machine but on older CPUs that hurts.

Most of it is getting rid of int<->float and int<->double conversion. That's where we bleed the most.

I would expect ARM would benefit even more but I guess we do a lot less hit testing there.
Comment 13 Simon Fraser (smfr) 2019-01-31 20:41:48 PST
Comment on attachment 360823 [details]
Patch

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

> Source/WebCore/page/FrameViewLayoutContext.h:96
> +    RenderLayoutState* layoutState() const PURE_FUNCTION;

What does PURE_FUNCTION do?
Comment 14 Simon Fraser (smfr) 2019-01-31 20:42:43 PST
(In reply to Benjamin Poulain from comment #12)
> Most of it is getting rid of int<->float and int<->double conversion. That's
> where we bleed the most.

I bet we have TONS of LayoutRect <-> FloatRect <-> IntRect conversions in various places. Is there any way to find the hotspots?
Comment 15 Benjamin Poulain 2019-01-31 20:50:28 PST
(In reply to Simon Fraser (smfr) from comment #13)
> Comment on attachment 360823 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=360823&action=review
> 
> > Source/WebCore/page/FrameViewLayoutContext.h:96
> > +    RenderLayoutState* layoutState() const PURE_FUNCTION;
> 
> What does PURE_FUNCTION do?

We tell the compiler that the return value only depends on its parameters, and global memory. AND that the function does not change the state of the program.

Since we do not change the memory of FrameViewLayoutContext between the two calls, the compiler is allowed to reuse the value of the first call.

The doc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes
A good Stackoverflow: https://stackoverflow.com/questions/29117836/attribute-const-vs-attribute-pure-in-gnu-c

> I bet we have TONS of LayoutRect <-> FloatRect <-> IntRect conversions in
> various places. Is there any way to find the hotspots?

I suspect you are right.

I don't have an idea to find the bad ones though.
Comment 16 Benjamin Poulain 2019-02-01 18:44:22 PST
Created attachment 360945 [details]
Patch
Comment 17 Benjamin Poulain 2019-02-01 18:45:10 PST
I added a fast int->unsigned since that was used in an API test.

Also added some tests for the new functions.
Comment 18 Simon Fraser (smfr) 2019-02-02 11:50:08 PST
It's probably better to fork the clamp changes into their own bug (Darin might have opinions).
Comment 19 Darin Adler 2019-02-03 11:28:54 PST
I agree that we should separate out the clampTo fixes; I’d think we’d want to land them first, and then go on to the optimizations that are built on them. Even if it’s just for regression testing and future bisection if no other reason.

I haven’t studied the behavior changes in clampTo yet -- I understand the principle but not the details of how the function needs to be used differently. I see many call sites changing and the regression tests alone don’t make it clear to me what changed about how it has to be used and what results you get.

The idea of making it more efficient without changing behavior is fantastic. I almost wish that any changes on how it has to be used or implements in behavior could be separate from a patch that was purely about performance and didn’t require changes at call sites. That could take the form of a patch that changes call sites without affecting behavior or performance. Then another that affects performance without changing behavior. Or whatever sequence we can make like that. Again, better for later bisection to see if any problems were caused.
Comment 20 Benjamin Poulain 2019-02-03 11:33:54 PST
Sounds good. I'll make a separate clampTo() patch with better explanations and testing.
Comment 21 Benjamin Poulain 2019-02-04 21:06:30 PST
Created attachment 361155 [details]
Patch
Comment 22 WebKit Commit Bot 2019-02-05 00:52:10 PST
Comment on attachment 361155 [details]
Patch

Clearing flags on attachment: 361155

Committed r240968: <https://trac.webkit.org/changeset/240968>
Comment 23 WebKit Commit Bot 2019-02-05 00:52:12 PST
All reviewed patches have been landed.  Closing bug.