Subject: Lag

From: Daniel van Vugt <[email-masked]>
Date: Thu, 08 Jan 2015 12:18:44 +0800

Hi all,

I've been dabbling in reducing Mir's lag for about a year now. It's 
something that only gets limited attention in my spare time so might 
benefit from other people getting involved...

End-to-end, Mir's (Unity8's) lag is about 6 frames. This is the sum of:
   Client: 2 frames lag (triple buffered)
   Nested server: 2 frames lag (triple buffered)
   Physical server: 2 frames lag (triple buffered)

One frame is usually about 16.6ms so we're talking about 100ms of lag in 
Unity8 right now. But there are some efforts under way to resolve this:

Physical server:
Short term: Reduce lag from 2 to 1 frame. Merge proposal up for review:
   https://code.launchpad.net/~vanvugt/mir/mesa-double/+merge/245723
Long term: Try experimentally reducing lag from 1 to almost-0 frames. 
This would be achievable only on systems fast enough to do their whole 
render during or just before the vblank period. Sounds far-fetched but 
this is how many of us got started in graphics so it's definitely possible.

Nested server:
For optimal lag, ideally we wouldn't have nesting. However we can get 
the nesting overhead down from 2 frames lag to 1 in the next paragraph. 
Because a nested server is really just a client.

Client:
All clients are triple buffered right now, making the visible lag 2 
frames before it even gets to the nested server. But most clients don't 
need this many buffers. I'm working on an adaptive approach that 
(instead of actually reducing the queue size) just throttles the 
producer (client) in a way that it's never more than one frame away from 
the consumer (nested server). This still needs work but lives here:
   https://code.launchpad.net/~vanvugt/mir/ddouble

Realistically, I expect us to get Unity8's lag down from 6 frames to 
around 3 this year. However that's still more than extreme cases like 
Oculus Rift requires.

Oculus have repeatedly said their magic threshold is 20ms, so to meet 
that standard we'd have to get lag down to 1 frame end-to-end. And it is 
theoretically possible for Mir too, if compositing got to 0, nesting was 
eliminated, and client lag only 1 (double buffered). Actually nesting 
wouldn't need to be eliminated if we could somehow pass-through overlays 
asynchronously and make nested servers almost zero lag.

- Daniel