From dce6b6df50b5f386aa7b2455507e56fad9dff15e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 31 Jan 2026 19:00:56 +0000 Subject: [PATCH] optimize: Replace XSync with XFlush in resizeclient and drw_map This change replaces blocking `XSync` calls with non-blocking `XFlush` in `resizeclient` (used in animations and resizing) and `drw_map` (used in bar drawing). - `XSync` forces a round-trip to the X server, waiting for it to process requests. This introduces significant latency in tight loops like `animateclient` (which runs at ~60fps). - `XFlush` sends the requests to the server asynchronously, allowing the client to continue processing immediately. This optimization improves the smoothness of window animations, resizing, and dragging, and reduces latency in status bar updates. Verified that the application compiles successfully with `make clean && make`. Co-authored-by: paperbenni <15818888+paperbenni@users.noreply.github.com> --- .jules/bolt.md | 3 +++ client.c | 5 ++++- drw.c | 5 ++++- 3 files changed, 11 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..1ac54324 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2026-01-31 - XSync vs XFlush in X11 Animations +**Learning:** `XSync(dpy, False)` is a blocking round-trip to the X server, while `XFlush(dpy)` sends requests asynchronously. In tight loops like animations (`animateclient` in `animation.c`) or interactive resizing (`resizeclient` in `client.c`), `XSync` can significantly degrade frame rates by forcing the client to wait for the server on every frame. +**Action:** Replace `XSync` with `XFlush` in performance-critical rendering/update paths where strict synchronization is not required for correctness. Ensure to verify that side effects (like event generation) are not implicitly relied upon by subsequent synchronous checks. diff --git a/client.c b/client.c index 13f1e27f..7bb19b30 100644 --- a/client.c +++ b/client.c @@ -279,7 +279,10 @@ 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); + /* Optimization: Use XFlush instead of XSync to avoid blocking round-trip to X server. + * This significantly improves performance during animations and mouse resizing. + */ + XFlush(dpy); } void updatetitle(Client *c) { diff --git a/drw.c b/drw.c index 7e99a386..ed067de0 100644 --- a/drw.c +++ b/drw.c @@ -494,7 +494,10 @@ 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); + /* Optimization: Use XFlush instead of XSync to avoid blocking round-trip. + * XCopyArea is efficient, and we just need to ensure the request is sent. + */ + XFlush(drw->dpy); } unsigned int drw_fontset_getwidth(Drw *drw, const char *text) {