Skip to content

⚡ Bolt: Optimize X11 rendering synchronization#188

Open
paperbenni wants to merge 1 commit intodevfrom
bolt-optimize-xsync-4662875173923124850
Open

⚡ Bolt: Optimize X11 rendering synchronization#188
paperbenni wants to merge 1 commit intodevfrom
bolt-optimize-xsync-4662875173923124850

Conversation

@paperbenni
Copy link
Member

@paperbenni paperbenni commented Jan 31, 2026

⚡ Bolt: [performance improvement]

💡 What: Replaced blocking XSync(dpy, False) with asynchronous XFlush(dpy) in client.c (resizeclient) and drw.c (drw_map).

🎯 Why:

  • resizeclient is called frequently during animations and interactive resizing. XSync forces a round-trip wait on every frame, causing stutter and limiting frame rate.
  • drw_map is called for every bar update. XSync here 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:

  • Verified compilation with make clean && make.
  • Checked code paths to ensure XSync was not relied upon for strict synchronization before dependent operations (e.g. resizeclient updates 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:

  • Reduce latency in window resizing and animations by replacing blocking XSync calls with non-blocking XFlush in core rendering and layout paths.

Chores:

  • Add an internal Bolt note documenting the XSync vs XFlush behavior and guidance for performance-critical X11 code paths.

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>
@google-labs-jules
Copy link
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 31, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Replaces 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 optimization

sequenceDiagram
  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
Loading

Sequence diagram for drw_map bar rendering before vs after XSync optimization

sequenceDiagram
  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
Loading

File-Level Changes

Change Details Files
Optimize window resize path by avoiding blocking X11 round-trips.
  • Replace XSync with XFlush after XConfigureWindow and configure() in resizeclient to avoid per-call blocking.
  • Add brief inline comment explaining the performance rationale and impact on animations and mouse resizing.
client.c
Optimize bar drawing path to send copy requests asynchronously instead of synchronously waiting.
  • Replace XSync with XFlush after XCopyArea in drw_map to prevent unnecessary blocking after bar redraws.
  • Add inline comment clarifying that XCopyArea just needs the request sent and not a full sync.
drw.c
Document learning and guidelines around XSync vs XFlush usage in animations and tight loops.
  • Add .jules/bolt.md capturing the performance characteristics of XSync vs XFlush in animation and interactive resizing paths.
  • Record an action guideline to replace XSync with XFlush in performance-critical paths when strict synchronization is not required and to verify side-effect assumptions.
.jules/bolt.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link

coderabbitai bot commented Jan 31, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bolt-optimize-xsync-4662875173923124850

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant