[pr-performance] The prelude worker follows the helpers' priority, like the other threads the submitting thread waits for #322

Open
iridiumlotus wants to merge 2 commits from iridiumlotus/Darner:prelude-raised into main
Contributor

What it changes

  • The problem on main: a frame timeline (DARNER_TIMELINE, diagnostics build of main f3840d7 plus #216) on an 8-core CPU, standing still in the open world: the submitting thread waits 7.7 ms a frame for darner-prelude in ten waits (WaitOnAddress at host::Host::submit < host::Host::send_late, ended by darner-prelude), while that thread runs only 4.4 ms a frame. On the chain each frame's present came out of, darner-prelude stands "woken, not running yet" for about 3.9 ms a frame (15.6 ms in the four frames sampled), more than half of the chain's 6.8 ms a frame of "woken, not running yet".

DARNER_ASYNC_PRELUDES (on by default) records a submission's preludes on a worker thread, and the submitting thread joins it before it sends. The submitting thread runs above normal priority (or as DARNER_SUBMIT_PRIORITY says, or highest on a core of its own), and the other threads it waits for are raised as well by the helpers' priority policy (DARNER_HELPERS_RAISED, on by default: above normal, or the number in DARNER_HELPER_PRIORITY; darner-wide, the land pools, darner-heap-sync, darner-aside, ...). The prelude worker was started at normal priority, so on a CPU where the title's threads and the list translators keep every core busy it waits for a processor while the submitting thread waits for it. That is the case DARNER_HELPERS_RAISED was made for (its comment in cores.rs describes it on a 6-core CPU); this thread was not on its list.

This gives the prelude worker a cores::Priority, kept before each batch of preludes like the other helpers, so it follows the same policy they do: with DARNER_HELPERS_RAISED on (the default) above normal, or the number in DARNER_HELPER_PRIORITY if one is given; with it off, normal. The submitting thread's own priority (DARNER_SUBMIT_PRIORITY, highest on a dedicated core) is not copied. Five lines in host.rs plus the comment there; the helpers_raised comment lists the thread and the measurement.

Not in this PR: keeping the worker on the fast cores of a hybrid CPU (keep_on_fast_cores), which the other helpers also ask for. I have no hybrid CPU to measure it on.

How it was tested

  • Tested revision: d0bd297 (this branch, on main f3840d7) for the clippy gates and the policy check; the tests ran on its parent 6ffc294 (the head only rewords a code comment, after the review comment below). In the game: a release build of 270e8bf, the same code (the later commits differ only in comments and in the commit message), with scripts\play-nvidia.ps1 -NoMenu -Dlss ultraperformance: loaded the save and stood in the world for the 2 minutes of the run, 0 errors; read from outside the process 150 s after the start, darner-prelude is at thread priority 1, as darner-submit, darner-aside, darner-wide-0, darner-late-wait, darner-relay and darner-list-0 are.

  • Commands and results: the A/B below; gates further down.

  • Changes a default: yes, for everyone with DARNER_ASYNC_PRELUDES and DARNER_HELPERS_RAISED at their defaults (both on). It changes one thread's priority. Expected to matter where the CPU is fully busy (8 cores or fewer) and to do nothing where a core is free for the worker anyway.

  • A/B result: in-run A/B with DARNER_AB (same run, same scene, the switch flipped every 7 or 10 seconds). DARNER_AB can only flip DARNER_HELPERS_RAISED for all helpers at once, so these numbers are from an experiment build: main f3840d7 plus #216 plus this change behind a temporary switch of its own (not in this PR), built with --release --features ab. In it the worker's priority read from outside flips between 0 and 1 with the phases while the other threads stay at 1. Ryzen 7 5800X3D (8 cores, 16 threads), RTX 5080, 32 GB, Windows 11; scripts\play-nvidia.ps1 -NoMenu -Dlss ultraperformance (Series X profile, 2560x1440 output, scene 853x480, no ray tracing, no frame generation; the launcher sets DARNER_HELPER_PRIORITY=1, and the submitting thread is at 1 as well: no dedicated core, no DARNER_SUBMIT_PRIORITY), standing still in the open world on a daytime save, copied fresh from a backup for each run; 13.4 of the 16 logical processors busy. The scene's draw count moves between 6,700 and 14,600 a frame in a 60-second cycle, so each phase's mean frame time is fitted as a + b * draws + effect (A = the fit's value with the worker at normal priority; B - A = the effect):

    A (worker at normal priority) B - A (worker raised)
    Run 1: 7 s phases, 79 phases 42.1 ms at 9,772 draws (23.8 fps) -1.9 ms +-0.2 (-4.5 %)
    Run 1, the 47 phases under 9,100 draws 38.5 ms at 7,976 draws -2.5 ms +-0.2 (-6.6 %)
    Run 2: 7 s phases, 77 phases 42.6 ms at 9,935 draws -1.4 ms +-0.3 (-3.2 %)
    Run 3: 10 s phases, 54 phases 42.9 ms at 9,665 draws -1.8 ms +-0.2 (-4.1 %)
    Run 4: 10 s phases, two switches, 29 phases (7 with only this one on) 44.8 ms at 10,267 draws -2.7 ms +-0.5 (-6.1 %)
    Run 5: 10 s phases, DARNER_ASYNC_PRELUDES as the second switch, 29 phases 46.5 ms at 11,099 draws -1.7 ms +-0.8 (-3.7 %)

    Run 1 is the one to go by: it has every other thread as the launcher sets it. In runs 2 to 5 the experiment build also held darner-late-wait and darner-relay at priority 0 (the launcher's DARNER_HELPER_PRIORITY=1 has them at 1; a sixth run that flipped those two showed nothing: +0.8 ms +-0.8 and -0.5 ms +-0.8). With 10 s phases the A/B cycle is in step with the scene's 60-second cycle, so the busy stretch fell on the same side every time and the fit over draws has to carry that; runs 1 and 2 have 7 s phases for that reason. In run 5, DARNER_ASYNC_PRELUDES=0 is -0.5 ms +-0.7 against the worker at normal priority.

    Also tried and left out because it adds nothing on top of the raise: the submitting thread recording the preludes itself when the worker has not begun them (-1.5 ms +-0.5 alone).

  • Gates run (the three in AGENTS.md; there is no CI): cargo clippy --workspace --all-targets --locked -- -D warnings passed; the same with --all-features passed; cargo xtask policy passed (555 files ok); those three on d0bd297. cargo test --workspace --locked --no-fail-fast on 6ffc294 did not pass as a whole on this PC: every package passes except three tests outside this change (it touches host.rs and a comment in cores.rs, both in darner-gpu):

    • darner-gpu: 1,772 passed, 1 failed: watch::tests::ask_once_by_res_splits_reservations_without_refusals. It or watch::watch_pipe_epoch_tests::ask_once_delta_reask_direct_carves_refreshes_and_updates_page_epochs fails in most full runs of the package here, on main f3840d7 without this change as well (3 full runs of 3 on main; 3 of 4 on this branch, the fourth all passed), and the first passes when run alone (3 of 3).
    • darner-shader: 556 passed, 1 failed: emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders (the fixture #227 fixes; it fails on main here too, see #216).
    • darner-shader oracle64::legacy_mul_forms_are_exact did not finish: it goes through every float in a debug build; I stopped it after 25 minutes and ran the rest of the package without it.
  • Gameplay, when relevant: RTX 5080, Series X profile, 2560x1440, DLSS ultra performance, no frame generation, no ray tracing.

  • Shader wave sizes tested, when relevant: not relevant.

  • Hardware dependence: may depend on the CPU. Measured on 8 cores / 16 threads. Untested on CPUs with more cores, on hybrid CPUs, and with the submitting thread on a dedicated core (dual-CCD V-Cache CPUs), where it runs at highest priority and the worker stays at the helpers' priority.

  • Coverage gaps: one scene (standing still, daytime), one PC. Not measured while driving or in cutscenes. Not measured with DARNER_SUBMIT_PRIORITY or DARNER_HELPER_PRIORITY set to anything but the launcher's values. The frame times are from the experiment build described above, not from this exact commit; this commit's exe is not comparable run against run yet (it is a new build here, and its first runs still made pipelines).

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found for prelude, ASYNC_PRELUDES, HELPERS_RAISED or thread priority (open and closed, 2026-12-04). #274 also changes host.rs, in another place (the retirement queues).
  • Replaces or overlaps: none found
## What it changes - The problem on main: a frame timeline (`DARNER_TIMELINE`, diagnostics build of main `f3840d7` plus #216) on an 8-core CPU, standing still in the open world: the submitting thread waits **7.7 ms a frame** for `darner-prelude` in ten waits (`WaitOnAddress at host::Host::submit < host::Host::send_late`, ended by `darner-prelude`), while that thread runs only 4.4 ms a frame. On the chain each frame's present came out of, `darner-prelude` stands "woken, not running yet" for about 3.9 ms a frame (15.6 ms in the four frames sampled), more than half of the chain's 6.8 ms a frame of "woken, not running yet". `DARNER_ASYNC_PRELUDES` (on by default) records a submission's preludes on a worker thread, and the submitting thread joins it before it sends. The submitting thread runs above normal priority (or as `DARNER_SUBMIT_PRIORITY` says, or highest on a core of its own), and the other threads it waits for are raised as well by the helpers' priority policy (`DARNER_HELPERS_RAISED`, on by default: above normal, or the number in `DARNER_HELPER_PRIORITY`; `darner-wide`, the `land` pools, `darner-heap-sync`, `darner-aside`, ...). The prelude worker was started at normal priority, so on a CPU where the title's threads and the list translators keep every core busy it waits for a processor while the submitting thread waits for it. That is the case `DARNER_HELPERS_RAISED` was made for (its comment in `cores.rs` describes it on a 6-core CPU); this thread was not on its list. This gives the prelude worker a `cores::Priority`, kept before each batch of preludes like the other helpers, so it follows the same policy they do: with `DARNER_HELPERS_RAISED` on (the default) above normal, or the number in `DARNER_HELPER_PRIORITY` if one is given; with it off, normal. The submitting thread's own priority (`DARNER_SUBMIT_PRIORITY`, highest on a dedicated core) is not copied. Five lines in `host.rs` plus the comment there; the `helpers_raised` comment lists the thread and the measurement. Not in this PR: keeping the worker on the fast cores of a hybrid CPU (`keep_on_fast_cores`), which the other helpers also ask for. I have no hybrid CPU to measure it on. ## How it was tested - Tested revision: `d0bd297` (this branch, on main `f3840d7`) for the clippy gates and the policy check; the tests ran on its parent `6ffc294` (the head only rewords a code comment, after the review comment below). In the game: a release build of `270e8bf`, the same code (the later commits differ only in comments and in the commit message), with `scripts\play-nvidia.ps1 -NoMenu -Dlss ultraperformance`: loaded the save and stood in the world for the 2 minutes of the run, 0 errors; read from outside the process 150 s after the start, `darner-prelude` is at thread priority 1, as `darner-submit`, `darner-aside`, `darner-wide-0`, `darner-late-wait`, `darner-relay` and `darner-list-0` are. - Commands and results: the A/B below; gates further down. - Changes a default: yes, for everyone with `DARNER_ASYNC_PRELUDES` and `DARNER_HELPERS_RAISED` at their defaults (both on). It changes one thread's priority. Expected to matter where the CPU is fully busy (8 cores or fewer) and to do nothing where a core is free for the worker anyway. - A/B result: in-run A/B with `DARNER_AB` (same run, same scene, the switch flipped every 7 or 10 seconds). `DARNER_AB` can only flip `DARNER_HELPERS_RAISED` for all helpers at once, so these numbers are from an experiment build: main `f3840d7` plus #216 plus this change behind a temporary switch of its own (not in this PR), built with `--release --features ab`. In it the worker's priority read from outside flips between 0 and 1 with the phases while the other threads stay at 1. Ryzen 7 5800X3D (8 cores, 16 threads), RTX 5080, 32 GB, Windows 11; `scripts\play-nvidia.ps1 -NoMenu -Dlss ultraperformance` (Series X profile, 2560x1440 output, scene 853x480, no ray tracing, no frame generation; the launcher sets `DARNER_HELPER_PRIORITY=1`, and the submitting thread is at 1 as well: no dedicated core, no `DARNER_SUBMIT_PRIORITY`), standing still in the open world on a daytime save, copied fresh from a backup for each run; 13.4 of the 16 logical processors busy. The scene's draw count moves between 6,700 and 14,600 a frame in a 60-second cycle, so each phase's mean frame time is fitted as `a + b * draws + effect` (A = the fit's value with the worker at normal priority; B - A = the effect): | | A (worker at normal priority) | B - A (worker raised) | |---|---|---| | Run 1: 7 s phases, 79 phases | 42.1 ms at 9,772 draws (23.8 fps) | **-1.9 ms +-0.2 (-4.5 %)** | | Run 1, the 47 phases under 9,100 draws | 38.5 ms at 7,976 draws | -2.5 ms +-0.2 (-6.6 %) | | Run 2: 7 s phases, 77 phases | 42.6 ms at 9,935 draws | -1.4 ms +-0.3 (-3.2 %) | | Run 3: 10 s phases, 54 phases | 42.9 ms at 9,665 draws | -1.8 ms +-0.2 (-4.1 %) | | Run 4: 10 s phases, two switches, 29 phases (7 with only this one on) | 44.8 ms at 10,267 draws | -2.7 ms +-0.5 (-6.1 %) | | Run 5: 10 s phases, `DARNER_ASYNC_PRELUDES` as the second switch, 29 phases | 46.5 ms at 11,099 draws | -1.7 ms +-0.8 (-3.7 %) | Run 1 is the one to go by: it has every other thread as the launcher sets it. In runs 2 to 5 the experiment build also held `darner-late-wait` and `darner-relay` at priority 0 (the launcher's `DARNER_HELPER_PRIORITY=1` has them at 1; a sixth run that flipped those two showed nothing: +0.8 ms +-0.8 and -0.5 ms +-0.8). With 10 s phases the A/B cycle is in step with the scene's 60-second cycle, so the busy stretch fell on the same side every time and the fit over draws has to carry that; runs 1 and 2 have 7 s phases for that reason. In run 5, `DARNER_ASYNC_PRELUDES=0` is -0.5 ms +-0.7 against the worker at normal priority. Also tried and left out because it adds nothing on top of the raise: the submitting thread recording the preludes itself when the worker has not begun them (-1.5 ms +-0.5 alone). - Gates run (the three in AGENTS.md; there is no CI): `cargo clippy --workspace --all-targets --locked -- -D warnings` passed; the same with `--all-features` passed; `cargo xtask policy` passed (555 files ok); those three on `d0bd297`. `cargo test --workspace --locked --no-fail-fast` on `6ffc294` did not pass as a whole on this PC: every package passes except three tests outside this change (it touches `host.rs` and a comment in `cores.rs`, both in darner-gpu): - darner-gpu: 1,772 passed, 1 failed: `watch::tests::ask_once_by_res_splits_reservations_without_refusals`. It or `watch::watch_pipe_epoch_tests::ask_once_delta_reask_direct_carves_refreshes_and_updates_page_epochs` fails in most full runs of the package here, on main `f3840d7` without this change as well (3 full runs of 3 on main; 3 of 4 on this branch, the fourth all passed), and the first passes when run alone (3 of 3). - darner-shader: 556 passed, 1 failed: `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders` (the fixture #227 fixes; it fails on main here too, see #216). - darner-shader `oracle64::legacy_mul_forms_are_exact` did not finish: it goes through every float in a debug build; I stopped it after 25 minutes and ran the rest of the package without it. - Gameplay, when relevant: RTX 5080, Series X profile, 2560x1440, DLSS ultra performance, no frame generation, no ray tracing. - Shader wave sizes tested, when relevant: not relevant. - Hardware dependence: may depend on the CPU. Measured on 8 cores / 16 threads. Untested on CPUs with more cores, on hybrid CPUs, and with the submitting thread on a dedicated core (dual-CCD V-Cache CPUs), where it runs at highest priority and the worker stays at the helpers' priority. - Coverage gaps: one scene (standing still, daytime), one PC. Not measured while driving or in cutscenes. Not measured with `DARNER_SUBMIT_PRIORITY` or `DARNER_HELPER_PRIORITY` set to anything but the launcher's values. The frame times are from the experiment build described above, not from this exact commit; this commit's exe is not comparable run against run yet (it is a new build here, and its first runs still made pipelines). ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found for `prelude`, `ASYNC_PRELUDES`, `HELPERS_RAISED` or thread priority (open and closed, 2026-12-04). #274 also changes `host.rs`, in another place (the retirement queues). - Replaces or overlaps: none found
The submitting thread joins darner-prelude before it sends each submission,
and runs above normal priority, as the other threads it waits for do. The
prelude worker was started at normal priority: with every core busy it stood
ready without a processor while the submitting thread waited for it (7.7 ms
a frame in ten waits on an 8-core processor, the worker itself running 4.4).

It now keeps a cores::Priority like the other helpers. In-run A/B on that
processor, standing still in the open world: -1.9 ms a frame +-0.2 of 42.1
(-4.5 %).
First-time contributor

The implementation makes darner-prelude follow the existing helper priority policy. The submitting thread still reads DARNER_SUBMIT_PRIORITY and can use highest priority when it has a dedicated core. Could the title and the worker comment say that the prelude now follows the other helpers? That would describe the behavior under those overrides as well as the default used for the A/B.

The implementation makes `darner-prelude` follow the existing helper priority policy. The submitting thread still reads `DARNER_SUBMIT_PRIORITY` and can use highest priority when it has a dedicated core. Could the title and the worker comment say that the prelude now follows the other helpers? That would describe the behavior under those overrides as well as the default used for the A/B.
It follows the helpers' priority (cores::Priority: DARNER_HELPERS_RAISED, and
the number in DARNER_HELPER_PRIORITY if one is given), as the other threads the
submitting thread waits for do. The submitting thread's own priority
(DARNER_SUBMIT_PRIORITY, highest on a core of its own) is not copied. Comment
only.
iridiumlotus changed title from WIP: [pr-performance] The prelude worker runs at the submitting thread's priority, like the other threads it waits for to [pr-performance] The prelude worker follows the helpers' priority, like the other threads the submitting thread waits for 2026-12-04 15:17:32 +00:00
Author
Contributor

Thanks, you are right. The worker follows the helpers' priority policy (cores::Priority: DARNER_HELPERS_RAISED, and the number in DARNER_HELPER_PRIORITY if one is given); the submitting thread's own priority (DARNER_SUBMIT_PRIORITY, highest on a dedicated core) is not copied.

Changed: the worker's comment in host.rs says so now (d0bd297, comment only), and so do the title and the description. The A/B ran on the launcher's defaults, where the submitting thread and the helpers are both at 1; the description's coverage gaps now say that those overrides and a dedicated submit core were not measured.

Thanks, you are right. The worker follows the helpers' priority policy (`cores::Priority`: `DARNER_HELPERS_RAISED`, and the number in `DARNER_HELPER_PRIORITY` if one is given); the submitting thread's own priority (`DARNER_SUBMIT_PRIORITY`, highest on a dedicated core) is not copied. Changed: the worker's comment in `host.rs` says so now (d0bd297, comment only), and so do the title and the description. The A/B ran on the launcher's defaults, where the submitting thread and the helpers are both at 1; the description's coverage gaps now say that those overrides and a dedicated submit core were not measured.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'prelude-raised:iridiumlotus-prelude-raised'
git switch 'iridiumlotus-prelude-raised'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'iridiumlotus-prelude-raised'
git switch 'iridiumlotus-prelude-raised'
git rebase 'main'
git switch 'main'
git merge --ff-only 'iridiumlotus-prelude-raised'
git switch 'iridiumlotus-prelude-raised'
git rebase 'main'
git switch 'main'
git merge --no-ff 'iridiumlotus-prelude-raised'
git switch 'main'
git merge --squash 'iridiumlotus-prelude-raised'
git switch 'main'
git merge --ff-only 'iridiumlotus-prelude-raised'
git switch 'main'
git merge 'iridiumlotus-prelude-raised'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!322
No description provided.