Skip to content

Headless test waits leave the CPU to the work they wait for - #4201

Open
THEtheChad wants to merge 1 commit into
storytold:mainfrom
THEtheChad:fix/3981-busy-wait
Open

THEtheChad wants to merge 1 commit into
storytold:mainfrom
THEtheChad:fix/3981-busy-wait

Conversation

@THEtheChad

@THEtheChad THEtheChad commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Refs #3981

Problem

Three lightcraft-ui-egui tests fail under suite load and pass alone (#3981). Every expired wait finished later; nothing deadlocked or was lost. The headless harness added to the load itself: while the app was busy, settle, step_until and request drew a frame every 1 ms, each laying out the whole UI. On a 4-core run those frames took about half the test binary's CPU (2029 s of 4129 s), away from the renders and merges the tests were waiting for.

Change

  • crates/ui-egui/src/headless.rs: while busy(), the three loops call a new wait_for_work between frames. It waits up to BUSY_PAUSE (10 ms) for a render to finish (wait_for_worker), else sleeps the rest of the pause (a merge, file checks, input).
  • 10 ms is shorter than a simulated frame (1/60 s), so a busy app still runs ahead of real time, and a finished render ends the pause at once. step_until keeps its 1 ms pause when nothing is busy.

Tests

  • headless::tests::waits_pace_their_frames_while_a_render_is_out holds a render out and counts the frames a 300 ms settle and step_until draw. On main it failed 3 of 3 runs (74–92 frames, at most 32 allowed); it passes with the change. Load can only lower the count, so it can't flake toward failing.
  • Loaded 4-core runs of the ui-egui lib binary: CPU 4129 s → 2608 s, of which the waits' frames 2029 s → 571 s. Base runs failed 2 of 4, paced runs 0 of 3: too few to call the flake gone, so this refers to Flaky tests: import-thumbnail and merge-dialog previews don't settle within their budgets under suite load #3981 rather than closing it.
  • Rebased onto main 27b755a (includes Find Similar test: photos measured from memory aren't missing reads (#3823) #3824, which fixes the Find Similar test this change exposed more often): cargo xtask ci --quick (with craft-fonts) passed all 8 steps; cargo test -p lightcraft-ui-egui --lib 1937 passed; the find_similar and headless tests passed 5 runs in a row.
  • Not run: the full cargo xtask ci, macOS, Windows.

Notes

Summary by CodeRabbit

  • Performance
    • Improved headless frame pacing while rendering is in progress, reducing unnecessary short sleeps during settling, stepping, and requests.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Busy headless waits now use a shared helper that waits up to 10 ms for renderer work. A new test checks frame pacing for settle and step_until while a render is in flight.

Changes: Headless wait pacing

Layer / File(s) Summary
Wait for renderer work during busy loops
crates/ui-egui/src/headless.rs
settle, step_until, and request use wait_for_work while busy. The helper waits up to BUSY_PAUSE for renderer completion. step_until retains a 1 ms sleep while idle.
Test pacing during an in-flight render
crates/ui-egui/src/headless/tests.rs
A new test checks that settle and step_until do not complete within 300 ms and limits their frame counts while a render is in flight.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

Suggested reviewers: nledford, marcoarnulfo, oneslips

Merge Risk: Minimal · up to df3a1

This change paces busy headless test waits so more CPU is available to the renders being awaited. It affects only the test harness, not production behavior. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change in the headless test waits. The PR makes settle, step_until, and request pause between frames while the app is busy, so the CPU goes to the renders being awaited. The t…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change in the headless test waits. The PR makes settle, step_until, and request pause between frames while the app is busy, so the CPU goes to the renders being awaited. The title is specific and matches the changeset and objectives. It is a little abstract, but it is not misleading or off-topic.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 27b755a and df3a1a3.

Files selected for processing: 2

  • crates/ui-egui/src/headless.rs
  • crates/ui-egui/src/headless/tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@THEtheChad

Copy link
Copy Markdown
Contributor Author

Dropped the Find Similar test commit (1bd6fde1): #3824 fixes the same test for #3823, is approved, and checks more (every photo measured). Head is now 9dcf4874. This PR stays a draft until #3824 merges, then I'll rebase it; until then that test can fail here as #3823 describes.

settle, step_until and request drew a frame every millisecond while the
app was busy. On a loaded machine those frames took about half of the
ui-egui test binary's CPU, away from the renders and merges the tests
were waiting on, and three waits ran past their limits (storytold#3981).

While busy, the harness now waits for a render to finish, or 10 ms,
before the next frame. 10 ms is shorter than a simulated frame, so the
app still runs ahead of real time.

Refs storytold#3981
@THEtheChad THEtheChad changed the title Issue #3981: headless waits leave the CPU to the work they wait for Headless test waits leave the CPU to the work they wait for Nov 17, 2026
@THEtheChad
THEtheChad marked this pull request as ready for review November 17, 2026 19:59

@vangel76 vangel76 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed df3a1a33. No findings. I traced settling, waiting, and requests through the native-worker and no-worker paths, and checked the existing pacing regression.

Source review only. I did not build the project, run tests, or check CI.

@wanikhawar wanikhawar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The headless harness paces frames by pending work instead of redrawing every millisecond. Test-only.

This branch has not been deployed

No deployments
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.

3 participants