Re: [hackers] [st][PATCH] separate blinking timer from drawing in run()

2019-03-28 Thread Eric Pruitt
On Wed, Jan 02, 2019 at 02:50:15AM +0100, kais euchi wrote:
> 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.

I've been using this patch for several weeks, and it seems to resolve a
problem I observed where sometimes, in the middle of a screen refresh,
st would pause for a perceptible amount of time showing the screen in a
half-updated state.

Thanks for sharing,
Eric



Re: [hackers] [st][PATCH] separate blinking timer from drawing in run()

2019-01-02 Thread Silvan Jegen
Hi

[2019-01-02 02:50] kais euchi 
> This article [?] 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 [?] by avoiding 
> useless delay calculation making it also independent from the xfps setting.

I measured the difference on my machine (dwm on a Ryzen 7 1700X) and it
was quite a bit bigger:

# Title   Min   Max   Avg   SD
1 st normal without blinking  20.0  29.6  22.7  3.0
2 vim in st without blinking  20.1  29.5  21.8  1.1
3 st-patched normal without blinking  3.9   12.8  7.8   1.9
4 vim in st-patched without blinking  4.9   12.3  8.6   1.3

where "st normal" is just st running bash. It's somewhat suspect that
in the non-patched case the average latency of st running vim is lower
than with just bash. For now I will assume it was a statistical fluke.

All datapoints generated by typometer can be downloaded from here[0].

Not sure the difference is actually notable in practice but the average
latency is reduced to less than half on my machine. Looks nice! It comes
at a cost of a few more lines of code though.


Cheers,

Silvan

[0] https://sillymon.ch/data/resultspatchedandunpatched.csv



[hackers] [st][PATCH] separate blinking timer from drawing in run()

2019-01-01 Thread kais euchi
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 {
-