Bug 234104 - Momentum Generator: Scroll tail hiccup only when scrolling up on 60Hz displays
Summary: Momentum Generator: Scroll tail hiccup only when scrolling up on 60Hz displays
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: Tim Horton
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-12-09 14:43 PST by Tim Horton
Modified: 2021-12-09 16:18 PST (History)
3 users (show)

See Also:


Attachments
Patch (2.21 KB, patch)
2021-12-09 14:45 PST, Tim Horton
no flags Details | Formatted Diff | Diff
Patch (2.49 KB, patch)
2021-12-09 14:50 PST, Tim Horton
simon.fraser: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Horton 2021-12-09 14:43:27 PST
Momentum Generator: Scroll tail hiccup only when scrolling up on 60Hz displays
Comment 1 Tim Horton 2021-12-09 14:45:43 PST
Created attachment 446611 [details]
Patch
Comment 2 Tim Horton 2021-12-09 14:50:01 PST
Created attachment 446613 [details]
Patch
Comment 3 Tim Horton 2021-12-09 15:02:34 PST
https://trac.webkit.org/changeset/286805/webkit
Comment 4 Radar WebKit Bug Importer 2021-12-09 15:03:21 PST
<rdar://problem/86292894>
Comment 5 Darin Adler 2021-12-09 15:20:05 PST
Comment on attachment 446613 [details]
Patch

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

> Source/WebKit/WebProcess/WebPage/MomentumEventDispatcher.cpp:442
> +        if (!firstZeroIndex[axis])
> +            return;
> +
> +        if (deltas[axis][0] > 0)
> +            std::sort(deltas[axis].begin(), std::next(deltas[axis].begin(), firstZeroIndex[axis]), std::greater<float>());
> +        else
> +            std::sort(deltas[axis].begin(), std::next(deltas[axis].begin(), firstZeroIndex[axis]), std::less<float>());

Your "micro-style" choices here show a lack of love for local variables. I probably would have written this with a couple locals, just to make the code less verbose:

    auto begin = deltas[axis].begin();
    auto comparator = *begin > 0  ? std::greater<float>() : std::less<float>();
    std::sort(begin, std::next(begin, firstZeroIndex[axis]), comparator);

The check for 0 of firstZeroIndex is not needed for correctness, and presumably it’s also not an important optimization.
Comment 6 Tim Horton 2021-12-09 15:37:08 PST
(In reply to Darin Adler from comment #5)
> Comment on attachment 446613 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=446613&action=review
> 
> > Source/WebKit/WebProcess/WebPage/MomentumEventDispatcher.cpp:442
> > +        if (!firstZeroIndex[axis])
> > +            return;
> > +
> > +        if (deltas[axis][0] > 0)
> > +            std::sort(deltas[axis].begin(), std::next(deltas[axis].begin(), firstZeroIndex[axis]), std::greater<float>());
> > +        else
> > +            std::sort(deltas[axis].begin(), std::next(deltas[axis].begin(), firstZeroIndex[axis]), std::less<float>());
> 
> Your "micro-style" choices here show a lack of love for local variables. I
> probably would have written this with a couple locals, just to make the code
> less verbose:

Hehe, fair!

>     auto begin = deltas[axis].begin();
>     auto comparator = *begin > 0  ? std::greater<float>() :
> std::less<float>();
>     std::sort(begin, std::next(begin, firstZeroIndex[axis]), comparator);
> 
> The check for 0 of firstZeroIndex is not needed for correctness, and
> presumably it’s also not an important optimization.

I actually originally wrote something similar for the comparator (though inline...) but got

    incompatible operand types ('std::greater<float>' and 'std::less<float>')

(your suggestion does the same) and didn't want to fuss too much.
Comment 7 Darin Adler 2021-12-09 15:56:52 PST
(In reply to Tim Horton from comment #6)
> I actually originally wrote something similar for the comparator (though
> inline...) but got
> 
>     incompatible operand types ('std::greater<float>' and 'std::less<float>')
> 
> (your suggestion does the same) and didn't want to fuss too much.

Wow, so sad. Now I understand your choice.

For fun, I will research to see if this is a solvable problem. I’m sure one way is to use std::function as the result type, and clang, at least, is smart enough to still optimize and inline this even when std::function is involved. But writing out the std::function type might make things too ugly.
Comment 8 Darin Adler 2021-12-09 16:01:31 PST
Oh, I see why. std::greater<float> and std::less<float> are types, so of course the two types are two different types. Look how "beautiful" my solution is:

    auto comparator = *begin > 0
        ? std::function<bool(float,float)>(std::greater<float>())
        : std::less<float>();

Sadly not really good.
Comment 9 Darin Adler 2021-12-09 16:18:27 PST
Comment on attachment 446613 [details]
Patch

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

>>> Source/WebKit/WebProcess/WebPage/MomentumEventDispatcher.cpp:442
>>> +            std::sort(deltas[axis].begin(), std::next(deltas[axis].begin(), firstZeroIndex[axis]), std::less<float>());
>> 
>> Your "micro-style" choices here show a lack of love for local variables. I probably would have written this with a couple locals, just to make the code less verbose:
>> 
>>     auto begin = deltas[axis].begin();
>>     auto comparator = *begin > 0  ? std::greater<float>() : std::less<float>();
>>     std::sort(begin, std::next(begin, firstZeroIndex[axis]), comparator);
>> 
>> The check for 0 of firstZeroIndex is not needed for correctness, and presumably it’s also not an important optimization.
> 
> Hehe, fair!

Hey, today I learned this (from Anders):

   std::sort(deltas[axis].begin(), std::next(deltas[axis].begin(), firstZeroIndex[axis]), std::greater<>());

No need to specify "float".