Input events are not synchronized to the screen refresh
This bug report originated from a discussion with @exalm on a gtk#2025.
Videos
I re-posted here the videos from the gtk bug report since they demonstrate the issue quite nicely.
The first video demonstrates the situation today. Because the input events are not synchronized to the screen frame rate, panning the text box results in a jittery animation. The second video was taken with a proof-of-concept code aiming to solve the issue. It should be immediately apparent that the second animation is much smoother. For details about the proof-of-concept solution please refer to gtk#2025.
To watch the sessions please save each video to your computer and view it locally using mpv (due to some reason GNOME's totem doesn't resize to video). If you view the recordings online you won't be able to see the differences. Also, please make sure you are watching them on a 60FPS display.
This is a recording of the jittery scroll: jitter_window
This is a recording of the smooth scroll: smooth_window
The root cause
The root cause of the problem is that the input events are not synchronized to the screen refresh. For example, my external Apple 'trackpad' V1 generates around 90 scroll events per second. That means that on average, on a 60FPS display we get 1 scroll event on the first frame, 2 events on the second frame, 1 on the third, 2 on the forth etc, and sometimes we get 2 events twice in a row. If, for example, each event results in a 4px movement, we'll get 4px on the first frame, 8px on the second, 4px on the third etc. This causes a visible jitter.
Other input devices can cause a similar issue. For example, even a standard 125Hz USB mouse will lead to a jank frame about 5 times per second. That's because when using a standard 60Hz display, we'll get on average 2 input events per display frame, but for each second there are 5 'extra' input events (125 modulo 60).
Relevance to GNOME Shell
Some input events are directly handled by GNOME Shell/Mutter. Examples include moving the mouse, dragging windows, "stick-to-finger" touchpad gestures etc. GNOME Shell should interpolate the events that it consumes in order to achieve smooth mouse movement and other animations.
Events sent to the clients should not be altered. The reason is that some clients require minimum latency - games, for example. Other clients require all of the input events. For example a painting program will need the best event resolution possible in order to draw smooth curves. Clients that do require event interpolation will be able to use their toolkit (e.g. gtk) for that.
For further details please refer to gtk#2025. If required I can re-post the details here as well.