Bug 234104

Summary: Momentum Generator: Scroll tail hiccup only when scrolling up on 60Hz displays
Product: WebKit Reporter: Tim Horton <thorton>
Component: New BugsAssignee: Tim Horton <thorton>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch simon.fraser: review+

Tim Horton
Reported 2021-12-09 14:43:27 PST
Momentum Generator: Scroll tail hiccup only when scrolling up on 60Hz displays
Attachments
Patch (2.21 KB, patch)
2021-12-09 14:45 PST, Tim Horton
no flags
Patch (2.49 KB, patch)
2021-12-09 14:50 PST, Tim Horton
simon.fraser: review+
Tim Horton
Comment 1 2021-12-09 14:45:43 PST
Tim Horton
Comment 2 2021-12-09 14:50:01 PST
Tim Horton
Comment 3 2021-12-09 15:02:34 PST
Radar WebKit Bug Importer
Comment 4 2021-12-09 15:03:21 PST
Darin Adler
Comment 5 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.
Tim Horton
Comment 6 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.
Darin Adler
Comment 7 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.
Darin Adler
Comment 8 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.
Darin Adler
Comment 9 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".
Note You need to log in before you can comment on or make changes to this bug.