Skip to content

Scene: stop rebuilding outputs while another output waits for its flip - #395

Merged
joske merged 2 commits into
masterfrom
fix/388-per-output-structure-wake
Dec 1, 2026
Merged

joske merged 2 commits into
masterfrom
fix/388-per-output-structure-wake

Conversation

@joske

@joske joske commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Part of #388 (idle and desktop CPU).

With two or more outputs, a single window change made the other outputs rebuild the scene over and over while one output waited for its page flip. The structure flag was shared by all outputs and cleared only once every output had built, so each loop iteration rebuilt the outputs that were already done, found nothing to draw, and skipped. On a two-output Xfce desktop with the compositor off, one output built 159 times in a second for 8 window changes and 11 frames.

Each output now keeps its own structure wake. A change sets it on every output, an output clears its own when it builds, and an output waiting for a flip or a cursor commit keeps its wake until it can build. A deferred cursor retry wakes only its own output. Single-output setups are not affected.

Measured

Two outputs at different resolutions, Xfce with the compositor off, same actions on master plus counters and on this branch:

phase total builds builds on the output not waiting for a flip composites
menu hover 1806 → 578 1405 → 182 382 → 381
window drag 13690 → 4216 7694 → 1756 2002 → 2422
idle 92 → 52 78 → 26 14 → 26

During drag the remaining structure builds roughly match the real window changes. No visual differences.

Not fixed here: moving a window can still make one output rebuild for presentation damage while the other output waits for its flip. That is a separate follow-up.

Tests

structure_wake_is_consumed_per_output (paint_wake.rs): with output 0 waiting for a flip, a restack builds output 1 once; further ticks build nothing; output 0 builds after its flip retires; a second change builds output 1 once again. It fails on master at "further ticks build nothing". One tearing test now expects the paced output to keep its own cursor wake instead of clearing a shared flag.

🤖 Generated with Claude Code

joske and others added 2 commits December 1, 2026 16:34
scene_structure_dirty was one flag for all outputs and was cleared only
once every output had built. While one output waited for its page flip
or a cursor commit, every loop iteration re-admitted the other outputs:
they built, found no damage and skipped, until the flip retired. With two
outputs on hardware that was 159 structure builds for 8 structure changes
in one second.

Each output now holds its own structure wake. A raise sets it on every
output; an output consumes its own wake when it builds (Composed or
EmptyDamage); pre-build skips and failures keep it. scene_structure_dirty
now means "some output holds a wake".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The last direct write to scene_structure_dirty outside the tick raised the
flag without an output wake; with no wake held it woke every output, and
with one held it reached only that output. Wake the output whose cursor
transition was deferred instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joske

joske commented Dec 1, 2026

Copy link
Copy Markdown
Owner Author

@Samueru-sama Could you test on this branch 🙏

@Samueru-sama

Copy link
Copy Markdown
Contributor

Tested on real hardware: 3 outputs at 1440x900 (~79 Hz), i3 + polybar + fastcompmgr, one idle terminal. Base ef3bc7ac, branch 26689ce5, release builds, both with the same local discrete-RADV redirect-isolation patch used in the #388 runs, YSERVER_LOOP_TELEMETRY=1.

Method: 60 s idle, then 30 s with an override-redirect 300x200 window moved 60/40 px inside the left output at 12.5 moves/s. One session per side.

phase build cause master ef3bc7ac branch 26689ce5
idle structure, out0/1/2 79.6 / 73.3 / 70.8 per s 70.7 / 70.4 / 70.2 per s
idle CPU, one core 8.42% 7.58%
probe structure, out0/1/2 96.4 / 89.0 / 86.0 per s 85.7 / 85.5 / 85.0 per s
probe CPU, one core 10.34% 10.44%

Presentation builds were unchanged: 44.7/s per output idle and about 49/s during the probe.

The wake is consumed per output as intended: on this branch all outputs build at the same rate, while master builds the window's output more than the others. The saving here is only 5-6% of structure builds, and probe CPU is unchanged. The idle CPU difference is within the session-to-session spread I have seen on this machine (0.4-0.6 points), so I would not read it as a win.

Likely reason: fastcompmgr keeps every output presenting, about 45 presentation builds/s per output, so each output has work regardless of its structure wake. The large reductions in the description come from a two-output Xfce desktop with the compositor off, where the non-moving outputs are otherwise idle. I have not tested compositor-off or direct scanout.

The new structure_wake_is_consumed_per_output test and the updated tearing test pass here on RADV, as do the non-ignored yserver and yserver-render tests.

@joske
joske merged commit 66c32d6 into master Dec 1, 2026
20 of 22 checks passed
@joske

joske commented Dec 1, 2026

Copy link
Copy Markdown
Owner Author

Thanks, that's very useful. I've merged this as a targeted fix, since it removes the redundant rebuilds where outputs are otherwise idle, and #388 stays open for the rest.

Your numbers raise two questions. If you have time for another round:

  1. Does the compositor explain the small effect? Run the same drag probe on master and on ef3bc7ac (the commit before this PR) with fastcompmgr off, keeping the three outputs and the RADV patch as they were.
  2. What raises structure about 70 times a second per output at idle? On an idle desktop that is real work, not the bug fixed here. The branch diag/scene-structure-raises is current master plus counters, with no behaviour change. With YSERVER_LOOP_TELEMETRY=1 the render_telemetry line gains structure_raise/s[total= first= site=file:line:TOTAL/FIRST ...], which names the code that raises it. Our guess is the wake after each PresentPixmap from the GL wallpaper and fastcompmgr, but we haven't measured it. Please run your normal compositor-on idle session on this branch for 60 s, and in the same interval:
    • take a perf record --call-graph fp profile (frame-pointer build, as before);
    • note the submit and flip rates from the same log.

The counter sites plus a profile from the same interval should tell us where to spend the next round.

@Samueru-sama

Copy link
Copy Markdown
Contributor

Second round, same machine: 3 outputs at 1440x900, RADV patch and -C force-frame-pointers=yes on every build, YSERVER_LOOP_TELEMETRY=1, one idle terminal, polybar and the wallpaper running. One session per row.

1. Compositor off (fastcompmgr stopped after login), ef3bc7ac vs master 66c32d6f. 60 s idle, then the same 30 s drag probe as before (12.5 moves/s).

phase metric ef3bc7ac master 66c32d6f
idle structure, out0/1/2 per s 77.1 / 70.3 / 68.8 60.9 / 60.9 / 60.5
idle CPU, one core 5.88% 5.63%
probe structure, out0/1/2 per s 78.6 / 84.0 / 83.9 66.3 / 69.2 / 69.2
probe CPU, one core 7.92% 7.75%

Without the compositor the structure builds drop 12-21% per output (5-6% with it). CPU moves about 0.2 points, inside the 0.4-0.6 point session-to-session spread I have seen here. Composite submits are about 133/s idle and 148/s during the probe on both builds. Presentation builds in the probe are uneven in both: out0 about 15-19/s, the other two about 105-109/s.

2. Idle raises, diag/scene-structure-raises (d46b7f0b), compositor on, 60 s. structure_raise averaged 76/s (first 67/s):

site per s
scene/tick.rs:393 (structure_raises.raise in the carried_out branch) 45.2
present_ext.rs:1524 (backend.mark_dirty() after the Present source wait) 22.2
present_ext.rs:786 0

Same interval: composite submits 146/s, frame presents 146/s, paint submits 474/s, each output building 68 structure + 45 presentation per s.

Profile from the same 60 s: 3175 samples, no single hot function. By DSO: yserver 56%, libvulkan_radeon 22%, libc 20%. Top symbols are clock_gettime 2.2%, malloc 2.2%, free 2.1%. Caveat: this kernel (perf_event_paranoid=2) rejected --call-graph fp for a normal user, so I recorded with -e cpu-clock:u --user-callchains --call-graph fp. That is user space only, with a software clock and no kernel samples.

The sites agree with your guess that the wake follows Present. I did not isolate the wallpaper from fastcompmgr, and the compositor-off runs used builds without the site counters. Direct scanout is untested.

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.

2 participants