# Make key repeat rate on Wayland more precise \(2\) \(\#43589\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/ae649c66ed45cbb6336a4df35bf234671f088b2c)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: ae649c66ed45cbb6336a4df35bf234671f088b2c

Requested commit: ae649c66ed45cbb6336a4df35bf234671f088b2c

Commit: ae649c66ed45cbb6336a4df35bf234671f088b2c

Tree: e701dca2a47560688ed77cf7d6eedbc13c9361f8

Author: Ole Jørgen Brønner

Committer: GitHub

## Message

```
Make key repeat rate on Wayland more precise (2) (#43589)

CLOSES  #39042

This is a reopening of #34985+. 

_Original descrioption_:

In Wayland, the client implement key repeat themself. In Zed this is
ultimately handled by the gpui crate by inserting a timer source into
the event loop which repeat itself if the key is still held down [1].

But it seems the processing of the repeated key event happen
synchronously inside the timer source handler, meaning the effective
rate become slightly lower (since the repeated timer is scheduled using
the 1/rate as delay).

I measured the event processing time on my laptop and it's typically
around 3ms, but sometimes spiking at 10ms. At low key repeat rates this
is probably not _very_ noticeable. I see the default in Zed is set to a
(measly) 16/s, but I assume most systems will use something closer to
25, which is a 40ms delay. So ~3ms is around 7.5% of the delay. At
higher rate the discrepancy become worse of course.

I can visible notice the spikes, and doing some crude stopwatch
measurements using gedit as a reference I can reproduce around 5-10%
slower rates in Zed.

IMO this is significant enough to warrant improving, especially since
some people can get quite used the repeat rate and might feel something
being "off" in Zed.

~~The suggested fix simply subtract the processing time from the next
delay timer.~~


[1] https://github.com/olejorgenb/zed/blob/32df726f3b7fa83e7399f6629c59e0a3f3fff125/crates/gpui/src/platform/linux/wayland/client.rs#L1355

Release Notes:

- Improved Wayland (Linux) key repeat rate precision
```

## Parents

- [36a3b41f53182c3b528d027de7270d3ea204d0ee](https://git.cafe/gitcafe/zed/commit/36a3b41f53182c3b528d027de7270d3ea204d0ee?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/ae649c66ed45cbb6336a4df35bf234671f088b2c?format=markdown)
