diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..1ac5432 --- /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 13f1e27..7bb19b3 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 7e99a38..ed067de 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) {