Hard numbers in the Wayland vs X11 input latency discussion

Date: 2025-01-26
Git: https://gitlab.com/mort96/blog/blob/published/content/00000-home/00016-wayland-input-latency.md

Yesterday, I read this blog post: Wayland Cursor Lag: Just give me a break already..., where a Linux user discusses their frustration with input latency under Wayland. They detailed their own subjective experience of the problem, but failed to produce hard evidence.

Even though I'm a very happy user of wayland overall, I share the blog post's author's subjective impression that there's more cursor lag under Wayland than under X11. In my opinion, their experiment was limited by their phone camera's 90 FPS, which really doesn't feel like it's enough to get conclusive numbers when we're talking about differences which are probably on the order of single screen refresh cycles.

So I thought: hey, I have a phone with a 240 FPS camera mode, I bet that's enough to get some conclusive results!

Spoilers: I was right.

Experiment design

I simply pointed my phone's camera at the screen and desk using my left hand, made sure to get the mouse cursor, the mouse and my right hand in frame, and recorded myself repeatedly flicking the mouse with my finger. I recorded myself flicking it 16 times under Wayland, logged out of the GNOME Wayland session and into a GNOME X11 session, then did the same there.

I then converted the two resulting video files into a series of JPEGs using ffmpeg (ffmpeg -i <input file> %04d.jpg), and counted from the first frame where I could see the mouse move until the first frame where I could clearly see that the cursor had moved.

I elected to include the start and end frame; so if I saw the mouse move in frame 1045, then I saw the cursor move in frame 1047, I would count that as 3 frames.

Here's an example which depicts a latency of 3 frames (requires JavaScript):

Hardware details:

Limitations

The main limitations of this experiment are:

All these factors introduce some uncertainty in the results. However, they should affect Wayland and X11 equally, so with enough data, it should all even out.

Update: Another caveat I should clearly point out is that there are many other Wayland compositors out there than GNOME's, and I have not tested them. For that matter, there are other GPU drivers out there than AMD's. Other compositors and other GPU drivers may show different results.

Results

Here's the data I captured:

Variant Video frames of latency Average Milliseconds Refreshes
GNOME X11 5 4 3 4 5 4 6 5 1 4 4 4 3 4 4 4 4 16.7 2.4
GNOME Wayland 6 5 6 5 5 6 6 4 8 6 5 5 5 6 5 6 5.5625 23.2 3.3

Wayland, on average, has roughly 6.5ms more cursor latency than X11 on my system. I don't have the statistics expertise necessary to properly analyze whether this difference is statistically significant or not, but to my untrained eye, it looks like there's a clear and consistent difference.

Interestingly, the difference is very close to 1 full screen refresh. I don't know whether or not that's a coincidence.

Here are the numbers in chart form:

Latency chart

Conclusion

In my mind, these results are conclusive proof that there is a difference in input latency between X11 and Wayland, at least with my hardware, and that the difference is large enough that it's plausible for some people to notice.

Further testing on more varied hardware and refresh rates is necessary to get a clear picture of how wide-spread the problem is and how large it is. It's likely that the magnitude of the difference varies based on factors such as which compositor is used and what the refresh rate of the screen is.

I probably won't undertake that further testing, because this is all very time intensive work. My goal was only to see if I could conclusively measure some difference.

Update: I want to add a note here about what this testing does not show. It does not show that there's higher input latency in general in Wayland compared to X11 in a way which affects, for example, games. It is possible that this added latency is entirely cursor-specific and that Wayland and X11 exhibit the exact same input latency in graphical applications and games. It is my understanding that the cursor is handled very differently from normal graphical applications. Further testing would be necessary to show whether Wayland has more input latency in games than X11.

Read More