From 16724ba3a49d3b950c431feefa34671a4c908044 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 13 Jan 2026 19:03:42 +0000 Subject: [PATCH] perf: replace XSync with XFlush in critical paths Replaces blocking XSync calls with non-blocking XFlush in `drw_map` (drawing) and `resizeclient` (window resizing). This significantly reduces latency and improves smoothness during animations and redraws by avoiding unnecessary round-trips to the X server. --- .jules/bolt.md | 3 +++ client.c | 2 +- drw.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..c480f229 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2026-01-13 - XSync vs XFlush in Window Managers +**Learning:** In X11 window managers, `XSync(dpy, False)` is a blocking call that waits for the X server to process all requests. This is often necessary for error handling or strict synchronization but is a major performance bottleneck for frequent operations like drawing or resizing. +**Action:** Use `XFlush(dpy)` instead of `XSync` where strict synchronization is not required (e.g., drawing `drw_map` or window configuration `resizeclient`). `XFlush` sends the requests to the server without waiting for a reply, significantly reducing latency and improving animation smoothness. diff --git a/client.c b/client.c index 13f1e27f..c03e6b4b 100644 --- a/client.c +++ b/client.c @@ -279,7 +279,7 @@ void resizeclient(Client *c, int x, int y, int w, int h) { XConfigureWindow(dpy, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc); configure(c); - XSync(dpy, False); + XFlush(dpy); } void updatetitle(Client *c) { diff --git a/drw.c b/drw.c index 7e99a386..e3f9501b 100644 --- a/drw.c +++ b/drw.c @@ -494,7 +494,7 @@ void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, } XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y); - XSync(drw->dpy, False); + XFlush(drw->dpy); } unsigned int drw_fontset_getwidth(Drw *drw, const char *text) {