[pr-performance][startup][shaders] Preload: slowest pipelines first, and chunks handed out as threads free up (DARNER_PRELOAD_SCHEDULE, off by default) #266

Manually merged
TrustNo1 merged 0 commits from Jesper-A/Darner:up-preload-schedule into main 2026-12-04 22:17:31 +00:00
Collaborator

Draft: no timing run, so no speed claim, and two of the three gates have not run. Branch up-preload-schedule, one commit (a1dde3cea) on main f3840d73d.

Refs #128

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: a cold preload ends with a tail. About 6 % of the pipelines carry about 70 % of the compile time (per blazecoding2009's data in #128, one Ryzen 7 8845HS laptop: 4,695 slow pipelines, about 72 % of worker time), and step 3 of the preload (warm::into_library) gives each thread a fixed stripe (skip(t).step_by(threads)). The thread that drew the slow pipelines finishes last while the others idle. In our logs of 2026-12-03 the end of step 3 ran 8, then 2, then 1 compile at a time, about 1 to 2 minutes (read from compile memory lines on our PC). With this change that tail should shrink; not measured. Step 2 (warm::run) already hands out chunks of 40 dynamically, but in key order, so a slow chunk can start late.
  • What this does, with DARNER_PRELOAD_SCHEDULE=1 (off by default):
    • New apps/darner/src/warm/schedule.rs. It reads slow-pipelines.txt (lines <key> <ms> for every pipeline that took 1 s or more; the longest line of a key counts) and sorts slowest first. Pipelines with no recorded time keep their old order after them.
    • Step 3: the whole list is sorted that way, and threads take the next chunk from a shared queue instead of a fixed stripe: 4 pipelines per chunk for the known-slow ones, 64 for the rest (known::make reads the pipeline book once per call, so the cheap ones go in larger chunks). Every pipeline is made once.
    • Step 2: the early group and the rest stay separate (early first, so a stopped preload keeps what runs draw first). Each group is sorted slow first. The 40-pipeline hand-out is unchanged.
    • The console prints how many pipelines of known time go first.
  • Switch off: the old stripes and the old order, no code path differs.
  • Not touched: fill_library (DARNER_WARM_SHARED=1 only) and step 1 (translate.rs, a different problem: a barrier between files).
  • Memory: step 3 stays one process with the same thread count, so its peak (4.4 to 9.8 GB private on our PC, compile memory lines of 2026-12-03) is not lowered. Starting the longest compiles together may raise the early peak a little; the memory gate still applies. If the tail shrinks (should; not measured), the high-memory period may be shorter. None of this is measured with the switch on.
  • Follow-up, not in this PR: compiling step 3's slow pipelines inside step 2's pool of child processes, which would lower the single-process peak. It touches the same marks code as #140 and my keep-marks branch.
  • A section in docs/findings.md.

How it was tested

  • Tested revision: a1dde3cea (on f3840d73d).

  • Commands and results:

    • cargo test -p darner --bin darner warm: 29 passed (includes the new tests in schedule.rs: reading the file, stable slowest-first order, chunks covering every place once).
    • cargo clippy --workspace --all-targets --locked -- -D warnings: clean.
    • cargo xtask policy: ok.
  • Changes a default: no.

  • A/B result: none. The switch is off by default and nothing was timed with it on, so this PR makes no speed claim. No timing run, so no gain is claimed.

    A (off) B (on)
    cold preload time, tail length, peak memory not measured for this change not measured
  • Gates run on that revision (the three in AGENTS.md; there is no CI): gate 1 only (cargo clippy --workspace --all-targets --locked -- -D warnings). Not run: the same with --all-features, and cargo test --workspace --locked.

  • Gameplay, when relevant: not run. No preload with the switch on.

  • Shader wave sizes tested, when relevant: not relevant (no shader change).

  • Hardware dependence: see Spec dependence.

  • Coverage gaps: any timing run, the length of the tail with the switch on, the memory peak with the longest compiles starting together (16 GB machines in particular), --all-features, the workspace tests.

Spec dependence

  • Likely general: the sort and the queue are plain scheduling and do not depend on the GPU. The tail should shrink on any PC where a few compiles are much longer than the rest; not measured.
  • May depend on our specs: the 6 % / 70 % split is per the data in #128 (not measured on our PC). The 1 to 2 minute tail was read from our logs of 2026-12-03 on a RTX 2070 SUPER 8 GB (Turing), driver 621.40, Ryzen 7 5800X (8C/16T), 32 GB, no ReBAR, Series S + DLSS Performance. The driver's compile times, and how much the order matters, depend on the driver and the number of physical cores. Memory behaviour on 16 GB is the open risk.
  • Untested elsewhere: AMD and Intel drivers, PCs with fewer cores or less RAM.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only). Not yet: no preload run with the switch on. The PR stays a draft until one is done.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md (cargo xtask policy: ok).
  • 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: #215 (ours, warm.rs), #142, #140 (ours), #235 (andrewpozdnakov7-jpg), #234 (same author, warm.rs).
  • Replaces or overlaps:
    • #215 and #234 also edit warm.rs. My edits are in into_library's thread loop, a short block in run after the candidates sort, and the new warm/schedule.rs. Conflicts are possible; not merged to check. This draft is posted as it is and will be rebased before WIP: comes off.
    • #142 (translate.rs): no shared files. #140 and #235: no shared files.
    • The up-preload-early-first and up-preload-keep-marks drafts (my own) change what runs first, and the marks code near run's to_make, respectively; adjacent, not the same lines.
    • No open or closed PR found that changes the order or hand-out: searched "preload", "warm-done", "DARNER_PRELOAD", "slow-pipelines".

This change was made with AI assistance (Claude Code).

Draft: no timing run, so no speed claim, and two of the three gates have not run. Branch `up-preload-schedule`, one commit (a1dde3cea) on `main` f3840d73d. Refs #128 ## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: a cold preload ends with a tail. About 6 % of the pipelines carry about 70 % of the compile time (per blazecoding2009's data in #128, one Ryzen 7 8845HS laptop: 4,695 slow pipelines, about 72 % of worker time), and step 3 of the preload (`warm::into_library`) gives each thread a fixed stripe (`skip(t).step_by(threads)`). The thread that drew the slow pipelines finishes last while the others idle. In our logs of 2026-12-03 the end of step 3 ran 8, then 2, then 1 compile at a time, about 1 to 2 minutes (read from `compile memory` lines on our PC). With this change that tail should shrink; not measured. Step 2 (`warm::run`) already hands out chunks of 40 dynamically, but in key order, so a slow chunk can start late. - What this does, with `DARNER_PRELOAD_SCHEDULE=1` (off by default): - New `apps/darner/src/warm/schedule.rs`. It reads `slow-pipelines.txt` (lines `<key> <ms>` for every pipeline that took 1 s or more; the longest line of a key counts) and sorts slowest first. Pipelines with no recorded time keep their old order after them. - Step 3: the whole list is sorted that way, and threads take the next chunk from a shared queue instead of a fixed stripe: 4 pipelines per chunk for the known-slow ones, 64 for the rest (`known::make` reads the pipeline book once per call, so the cheap ones go in larger chunks). Every pipeline is made once. - Step 2: the early group and the rest stay separate (early first, so a stopped preload keeps what runs draw first). Each group is sorted slow first. The 40-pipeline hand-out is unchanged. - The console prints how many pipelines of known time go first. - Switch off: the old stripes and the old order, no code path differs. - Not touched: `fill_library` (`DARNER_WARM_SHARED=1` only) and step 1 (`translate.rs`, a different problem: a barrier between files). - Memory: step 3 stays one process with the same thread count, so its peak (4.4 to 9.8 GB private on our PC, `compile memory` lines of 2026-12-03) is not lowered. Starting the longest compiles together may raise the early peak a little; the memory gate still applies. If the tail shrinks (should; not measured), the high-memory period may be shorter. None of this is measured with the switch on. - Follow-up, not in this PR: compiling step 3's slow pipelines inside step 2's pool of child processes, which would lower the single-process peak. It touches the same marks code as #140 and my keep-marks branch. - A section in `docs/findings.md`. ## How it was tested - Tested revision: a1dde3cea (on f3840d73d). - Commands and results: - `cargo test -p darner --bin darner warm`: 29 passed (includes the new tests in `schedule.rs`: reading the file, stable slowest-first order, chunks covering every place once). - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. - `cargo xtask policy`: ok. - Changes a default: no. - A/B result: none. The switch is off by default and nothing was timed with it on, so this PR makes no speed claim. No timing run, so no gain is claimed. | | A (off) | B (on) | |---|---|---| | cold preload time, tail length, peak memory | not measured for this change | not measured | - Gates run on that revision (the three in AGENTS.md; there is no CI): gate 1 only (`cargo clippy --workspace --all-targets --locked -- -D warnings`). Not run: the same with `--all-features`, and `cargo test --workspace --locked`. - Gameplay, when relevant: not run. No preload with the switch on. - Shader wave sizes tested, when relevant: not relevant (no shader change). - Hardware dependence: see Spec dependence. - Coverage gaps: any timing run, the length of the tail with the switch on, the memory peak with the longest compiles starting together (16 GB machines in particular), `--all-features`, the workspace tests. ## Spec dependence - Likely general: the sort and the queue are plain scheduling and do not depend on the GPU. The tail should shrink on any PC where a few compiles are much longer than the rest; not measured. - May depend on our specs: the 6 % / 70 % split is per the data in #128 (not measured on our PC). The 1 to 2 minute tail was read from our logs of 2026-12-03 on a RTX 2070 SUPER 8 GB (Turing), driver 621.40, Ryzen 7 5800X (8C/16T), 32 GB, no ReBAR, Series S + DLSS Performance. The driver's compile times, and how much the order matters, depend on the driver and the number of physical cores. Memory behaviour on 16 GB is the open risk. - Untested elsewhere: AMD and Intel drivers, PCs with fewer cores or less RAM. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). Not yet: no preload run with the switch on. The PR stays a draft until one is done. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md` (`cargo xtask policy`: ok). - [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: #215 (ours, `warm.rs`), #142, #140 (ours), #235 (andrewpozdnakov7-jpg), #234 (same author, `warm.rs`). - Replaces or overlaps: - #215 and #234 also edit `warm.rs`. My edits are in `into_library`'s thread loop, a short block in `run` after the candidates sort, and the new `warm/schedule.rs`. Conflicts are possible; not merged to check. This draft is posted as it is and will be rebased before `WIP:` comes off. - #142 (`translate.rs`): no shared files. #140 and #235: no shared files. - The `up-preload-early-first` and `up-preload-keep-marks` drafts (my own) change what runs first, and the marks code near `run`'s `to_make`, respectively; adjacent, not the same lines. - No open or closed PR found that changes the order or hand-out: searched "preload", "warm-done", "DARNER_PRELOAD", "slow-pipelines". This change was made with AI assistance (Claude Code).
With the switch set, the pipelines slow-pipelines.txt has a time for go first, longest first (stable; unknown ones keep their order after them), in step 2 (inside the early group and inside the rest) and in the library step. The library step's fixed stripes (skip(t).step_by(threads)) become a queue of chunks taken by whichever thread is free, so the 1 to 2 minute tail should shrink (not measured). Off: the old order and stripes.

This change was made with AI assistance (Claude Code).
Owner

Review of a1dde3ce (read only, not built or run). WIP draft: one ordering point to settle, otherwise sound.

Checked:

  • recorded_ms keeps the longest line per key and skips bad lines and NaN.
  • slow_first is a stable sort: known times longest first, unknown after them in their old order.
  • chunks covers every place exactly once. The tests check edge lengths, and 8 threads on one Queue.
  • In step 3 each chunk is made once (fetch_add on the index). The per-pipeline callback only touches atomics, so sharing &each across calls is fine.
  • With the switch off, the stripes and order are exactly as on main.
  • In step 2 the early/other split is kept and each part is sorted on its own. Good.

Points:

  1. Step 3 loses early-first. into_library sorts all early first, but slow_first(&mut all, ...) then re-sorts the whole list by time. Known-slow non-early pipelines then go before every early one. That doesn't matter while step 3 only saves at its end. With DARNER_PRELOAD_SAVE_EVERY set, though, a step 3 stopped part-way keeps fewer of the pipelines the game loads first. Split at the early boundary here as you do in step 2 (or say why not).
  2. The memory peak. Starting the longest compiles together on every thread is the case most likely to raise step 3's single-process peak (4.4 to 9.8 GB on your PC). Please include one 16 GB machine in the timing run, and check that the compile memory guard holds.
  3. What takes it off WIP: a cold-preload A/B with the switch off and on, timing the tail and the peak memory; then gates 2 and 3.

It merges cleanly with main (f3840d73), #153 and #228. It conflicts with #215 in warm.rs: both rewrite the into_library worker loop, and #215 replaces the is_multiple_of(500) print with its throttle. Rebase this on #215 and keep the throttle in the queue path. With #140, #264 and #267 it conflicts only in docs/findings.md.

No testcall-ok while it's a draft.

Review of a1dde3ce (read only, not built or run). WIP draft: one ordering point to settle, otherwise sound. **Checked:** - `recorded_ms` keeps the longest line per key and skips bad lines and NaN. - `slow_first` is a stable sort: known times longest first, unknown after them in their old order. - `chunks` covers every place exactly once. The tests check edge lengths, and 8 threads on one `Queue`. - In step 3 each chunk is made once (`fetch_add` on the index). The per-pipeline callback only touches atomics, so sharing `&each` across calls is fine. - With the switch off, the stripes and order are exactly as on main. - In step 2 the early/other split is kept and each part is sorted on its own. Good. **Points:** 1. **Step 3 loses early-first.** `into_library` sorts `all` early first, but `slow_first(&mut all, ...)` then re-sorts the whole list by time. Known-slow non-early pipelines then go before every early one. That doesn't matter while step 3 only saves at its end. With `DARNER_PRELOAD_SAVE_EVERY` set, though, a step 3 stopped part-way keeps fewer of the pipelines the game loads first. Split at the early boundary here as you do in step 2 (or say why not). 2. **The memory peak.** Starting the longest compiles together on every thread is the case most likely to raise step 3's single-process peak (4.4 to 9.8 GB on your PC). Please include one 16 GB machine in the timing run, and check that the `compile memory` guard holds. 3. **What takes it off WIP:** a cold-preload A/B with the switch off and on, timing the tail and the peak memory; then gates 2 and 3. It merges cleanly with main (f3840d73), #153 and #228. It conflicts with #215 in `warm.rs`: both rewrite the `into_library` worker loop, and #215 replaces the `is_multiple_of(500)` print with its throttle. Rebase this on #215 and keep the throttle in the queue path. With #140, #264 and #267 it conflicts only in `docs/findings.md`. No testcall-ok while it's a draft.
Jesper-A changed title from WIP: [pr-performance][startup][shaders] Preload: slowest pipelines first, and chunks handed out as threads free up (DARNER_PRELOAD_SCHEDULE, off by default) to [pr-performance][startup][shaders] Preload: slowest pipelines first, and chunks handed out as threads free up (DARNER_PRELOAD_SCHEDULE, off by default) 2026-12-04 22:06:59 +00:00
TrustNo1 manually merged commit 83fb39f92c into main 2026-12-04 22:17:31 +00:00
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!266
No description provided.