⚡ Bolt: Optimize X11 rendering synchronization#188
Conversation
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, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideReplaces blocking XSync calls with non-blocking XFlush in performance-critical X11 rendering paths and adds a short internal note documenting the rationale and guidance for similar optimizations. Sequence diagram for X11 resizeclient rendering before vs after XSync optimizationsequenceDiagram
actor User
participant WindowManager
participant XServer
rect rgb(230,230,230)
loop Animation_or_interactive_resize
User->>WindowManager: drag/resize or animation tick
WindowManager->>XServer: XConfigureWindow request
alt Before_optimization_XSync
WindowManager->>XServer: XSync(dpy, False)
XServer-->>WindowManager: Acknowledge and process all requests
WindowManager->>WindowManager: Continue next frame after round-trip
else After_optimization_XFlush
WindowManager->>XServer: XFlush(dpy)
XServer-->>XServer: Process queued requests asynchronously
WindowManager->>WindowManager: Continue next frame without waiting
end
end
end
Sequence diagram for drw_map bar rendering before vs after XSync optimizationsequenceDiagram
participant WMBar as BarRenderer_drw
participant Window
participant XServer
loop Bar_update
WMBar->>Window: XCopyArea drawable -> window
alt Before_optimization_XSync
WMBar->>XServer: XSync(dpy, False)
XServer-->>WMBar: Round-trip completion
WMBar->>WMBar: Proceed to next bar update after wait
else After_optimization_XFlush
WMBar->>XServer: XFlush(dpy)
XServer-->>XServer: Process copy requests asynchronously
WMBar->>WMBar: Immediately proceed to next bar update
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Switching from XSync to XFlush changes synchronization guarantees; double-check any downstream assumptions that a resize/bar update is complete before subsequent operations (e.g., focus changes, geometry-dependent calculations) and consider keeping a sync at higher-level boundaries if needed.
- Using XFlush in tight animation loops can increase the volume of outstanding X requests; consider whether you need a periodic throttle or occasional XSync in long-running sequences to avoid request queue buildup under heavy load.
- The new comments are fairly verbose for performance notes; you might tighten them to a single line each so the optimization intent is clear without adding too much noise to frequently-touched code paths.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Switching from XSync to XFlush changes synchronization guarantees; double-check any downstream assumptions that a resize/bar update is complete before subsequent operations (e.g., focus changes, geometry-dependent calculations) and consider keeping a sync at higher-level boundaries if needed.
- Using XFlush in tight animation loops can increase the volume of outstanding X requests; consider whether you need a periodic throttle or occasional XSync in long-running sequences to avoid request queue buildup under heavy load.
- The new comments are fairly verbose for performance notes; you might tighten them to a single line each so the optimization intent is clear without adding too much noise to frequently-touched code paths.
## Individual Comments
### Comment 1
<location> `.jules/bolt.md:3` </location>
<code_context>
+## 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.
</code_context>
<issue_to_address>
**suggestion (typo):** Consider rephrasing "Ensure to verify" to a more idiomatic form.
Consider changing it to "Ensure that you verify" or "Be sure to verify" for more natural, idiomatic wording.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| @@ -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. | |||
There was a problem hiding this comment.
suggestion (typo): Consider rephrasing "Ensure to verify" to a more idiomatic form.
Consider changing it to "Ensure that you verify" or "Be sure to verify" for more natural, idiomatic wording.
⚡ Bolt: [performance improvement]
💡 What: Replaced blocking
XSync(dpy, False)with asynchronousXFlush(dpy)inclient.c(resizeclient) anddrw.c(drw_map).🎯 Why:
resizeclientis called frequently during animations and interactive resizing.XSyncforces a round-trip wait on every frame, causing stutter and limiting frame rate.drw_mapis called for every bar update.XSynchere is unnecessary blocking.📊 Impact: Reduces per-frame latency during animations and resizing by eliminating network/process context switch overhead to the X server. Expected to significantly improve smoothness of window management operations.
🔬 Measurement:
make clean && make.XSyncwas not relied upon for strict synchronization before dependent operations (e.g.resizeclientupdates internal state immediately).PR created automatically by Jules for task 4662875173923124850 started by @paperbenni
Summary by Sourcery
Optimize X11 rendering paths by removing unnecessary blocking synchronization calls.
Enhancements:
Chores: