From 88f8d6ef351c01b646725b389e7f521494637e14 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 3 Feb 2026 19:22:58 +0000 Subject: [PATCH] Performance: Replace XSync with XFlush in drw_map Replaces the blocking `XSync(drw->dpy, False)` call with `XFlush(drw->dpy)` in `drw_map`. `XSync` forces a round-trip to the X server, causing the window manager to block until the server processes the drawing request. This is unnecessary for basic drawing operations and degrades responsiveness. `XFlush` ensures the request is sent without waiting for a reply. Impact: - Reduces latency during UI updates (bar drawing, etc.). - Eliminates unnecessary context switches and blocking I/O. Co-authored-by: paperbenni <15818888+paperbenni@users.noreply.github.com> --- .jules/bolt.md | 4 ++++ drw.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..130a3e90 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,4 @@ + +## 2026-02-03 - XSync in Drawing Loops +**Learning:** `XSync` forces a blocking round-trip to the X server, which is catastrophic for performance in frequently called drawing functions like `drw_map`. +**Action:** Replace `XSync` with `XFlush` in drawing routines where strict synchronization is not required. diff --git a/drw.c b/drw.c index 7e99a386..35362fcf 100644 --- a/drw.c +++ b/drw.c @@ -494,7 +494,9 @@ 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); + /* Performance: XFlush is sufficient here; XSync causes unnecessary blocking + * round-trips. */ + XFlush(drw->dpy); } unsigned int drw_fontset_getwidth(Drw *drw, const char *text) {