Subject: Re: bug#46350: 28.0.50; touchpad-scrolling-eats-lots-of-cpu-samples

From: Eli Zaretskii <[email-masked]>
Date: Sun, 07 Feb 2021 19:49:37 +0200

> From: Andrey Orst <[email-masked]>
> Date: Sun, 7 Feb 2021 20:23:09 +0300
> Cc: [email-masked]
> 
> > Add a call to 'message' to mwheel-scroll, and have it show a counter
> > that counts up?
> 
> I've did as you've suggested. When scrolling buffer of 1405 lines from
> bottom to the top (while emacs is unresponsive) mwheel-scroll function
> seems to be called about ~1351 times. Single fast flick over touchpad
> produces ~40 calls to mwheel-scroll.

1350 calls during what time, approximately? less than a second?

I don't think Emacs can scroll so fast, one line at a time.  Note that
when you scroll with the scroll-bar, Emacs doesn't call
scroll-up/down, it just goes to a suitably calculated buffer position.
Which is why scroll-bar scrolling is much faster.  But I don't see how
we can do something similar with the mouse-wheel, since it doesn't
allow to calculate the buffer position to go to; Emacs needs to do
that calculation itself, and that what makes the scrolling so much
slower.

> > What is the size of the buffer that it scrolls almost instantly to
> > BOB?  How many lines?
> 
> 1405 lines. I'm testing this on bundled lisp-mode.el

Which explains why it scrolls in one go: 1405 ≅ 1350.

So, once we've established that the touchpad injects 1-line scroll
requests at such a high rate, what else needs to be investigated here?