Hello everyone,
This article [0] made me wonder how to improve latency in st, and i
thought i would share this small modification for a non-blinking setup.
When blinktimeout is set to 0, it reduces latency by ca. 5ms [1] by avoiding
useless delay calculation making it also independent from the xfps setting.
Regards,
Kais
[0] : https://lwn.net/Articles/751763/
[1] using typometer, found here : https://pavelfatin.com/typing-with-pleasure/
---
x.c | 75 -
1 file changed, 40 insertions(+), 35 deletions(-)
diff --git a/x.c b/x.c
index 0422421..7afbab5 100644
--- a/x.c
+++ b/x.c
@@ -1816,25 +1816,48 @@ run(void)
if (FD_ISSET(xfd, ))
xev = actionfps;
- clock_gettime(CLOCK_MONOTONIC, );
- drawtimeout.tv_sec = 0;
- drawtimeout.tv_nsec = (1000 * 1E6)/ xfps;
- tv =
-
- dodraw = 0;
- if (blinktimeout && TIMEDIFF(now, lastblink) > blinktimeout) {
- tsetdirtattr(ATTR_BLINK);
- win.mode ^= MODE_BLINK;
- lastblink = now;
- dodraw = 1;
- }
- deltatime = TIMEDIFF(now, last);
- if (deltatime > 1000 / (xev ? xfps : actionfps)) {
- dodraw = 1;
- last = now;
+ if (blinktimeout) {
+ clock_gettime(CLOCK_MONOTONIC, );
+ drawtimeout.tv_sec = 0;
+ drawtimeout.tv_nsec = (1000 * 1E6)/ xfps;
+ tv =
+
+ dodraw = 0;
+ if (TIMEDIFF(now, lastblink) > blinktimeout) {
+ tsetdirtattr(ATTR_BLINK);
+ win.mode ^= MODE_BLINK;
+ lastblink = now;
+ dodraw = 1;
+ }
+ deltatime = TIMEDIFF(now, last);
+ if (deltatime > 1000 / (xev ? xfps : actionfps)) {
+ dodraw = 1;
+ last = now;
+ }
+
+ if (dodraw) {
+ if (!FD_ISSET(ttyfd, ) && !FD_ISSET(xfd,
)) {
+ if (blinkset) {
+ if (TIMEDIFF(now, lastblink) \
+ > blinktimeout)
{
+ drawtimeout.tv_nsec =
1000;
+ } else {
+ drawtimeout.tv_nsec =
(1E6 * \
+
(blinktimeout - \
+
TIMEDIFF(now,
+
lastblink)));
+ }
+ drawtimeout.tv_sec = \
+
drawtimeout.tv_nsec / 1E9;
+ drawtimeout.tv_nsec %=
(long)1E9;
+ } else {
+ tv = NULL;
+ }
+ }
+ }
}
- if (dodraw) {
+ if (dodraw || !blinktimeout) {
while (XPending(xw.dpy)) {
XNextEvent(xw.dpy, );
if (XFilterEvent(, None))
@@ -1848,24 +1871,6 @@ run(void)
if (xev && !FD_ISSET(xfd, ))
xev--;
- if (!FD_ISSET(ttyfd, ) && !FD_ISSET(xfd, )) {
- if (blinkset) {
- if (TIMEDIFF(now, lastblink) \
- > blinktimeout) {
- drawtimeout.tv_nsec = 1000;
- } else {
- drawtimeout.tv_nsec = (1E6 * \
- (blinktimeout - \
- TIMEDIFF(now,
- lastblink)));
- }
- drawtimeout.tv_sec = \
- drawtimeout.tv_nsec / 1E9;
- drawtimeout.tv_nsec %= (long)1E9;
- } else {
-