Skip to content

clutter: Deliver events sooner when possible

Daniel van Vugt requested to merge vanvugt/mutter:remove-input-lag into master

Previously all events would be queued and their processing deferred till the next master clock tick, at which point supersesed input events would be dropped and only the latest of each type used. This was great for minimizing CPU usage but had two drawbacks:

  • Clients would receive the next input event after it is already too late to make it to the next compositor frame.
  • Clients would receive a lower resolution event stream than the hardware is capable of.

We now instead scale performance dynamically according to available time. If there is enough idle time available then that will be used to deliver events immediately without delay. Otherwise event delivery will scale down to the old minimal-CPU behaviour.

This allows clients to receive input events sufficiently in advance of the next compositor frame that they can respond and redraw with one frame lower latency than before. It also allows clients higher resolution input, in case they are able to use it.

Diagram

  M = master clock tick (60Hz display)
  I = input event to the shell (standard 125Hz USB mouse)
  i = input event reaches the client
  R = rendering in the shell (assume 4ms)
  r = rendering in the client (assume 2ms)

  Total software latency is:  I -> M -> i -> r -> R
  For simplicity here we don't include hardware latencies.


BEFORE

   Time | 0         10        20        30        40 milliseconds
 -----------------------------------------------------------------
        |   I       I       I       I       I       I
        | M :.......:......M                M          
        | i                i                i
        | rr               rr........       rr
        | RRRR             RRRR      .......RRRR

            |-------|--------------------------|
            2       10                         37

          Observed lag is 27ms for continuous input (scrolling)
                       or 35ms for instantaneous input (button press)


AFTER

   Time | 0         10        20        30        40 milliseconds
 -----------------------------------------------------------------
        |   I       I       I       I       I       I
        | M :       :      M                M          
        |   i       i       i       i       i       i
        |   rr......rr?     rr      rr?     rr      rr?
        | RRRR        .....RRRR             RRRR

            |-------|---------|
            2       10        20

          Observed lag is 18ms for a swap interval 1 client (60Hz)
                       or 10ms for a swap interval 0 client (125Hz)
Edited by Daniel van Vugt

Merge request reports