perf(prepare): opt-in RAM guard for prepare worker counts #2727

Open
github-sync wants to merge 3 commits from github/pr/2727 into main
Owner

@yeetbot90 opened this pull request on GitHub · 2026-11-12 09:30 UTC · original

Summary

  • Add prepare_ram_mb and an opt-in HOOKSHOT_PREPARE_RAM_GUARD / RX_VK_PREPARE_RAM_GUARD that caps auto prepare worker counts by (avail - reserve) / worker_peak_MB.
  • Always apply a critical floor under ~2 GB available (2 workers) / ~1 GB (1 worker) so prepare does not thrash; explicit HOOKSHOT_SHADER_WORKERS still wins for A/B above that.
  • Tunables: HOOKSHOT_PREPARE_WORKER_MB (default 384, provisional), HOOKSHOT_PREPARE_RESERVE_MB / HOOKSHOT_MEM_RESERVE_GB. Documented in docs/development.md.

Depends on #2725 (this branch is stacked on it).

Test plan

  • python -I -B tests/test_prepare_pool_workers.py / test_prepare_cpus.py
  • CI: Python source checks green on Windows + Ubuntu (all four jobs).
  • Rebuild tip DLL; --prepare-shaders with HOOKSHOT_PREPARE_RAM_GUARD=1 HOOKSHOT_PREPARE_RESERVE_MB=10000 HOOKSHOT_PREPARE_WORKER_MB=2000 (+ RX_VK_GPL=1)
  • AMD RX 9070 XT log:
    • prepare resources ... RAM 14284 MB available / 31801 MB total, process 4792 MB (peak 7668), RAM guard on then preparing shaders on 2 workers (RAM guard, usable 24)
    • later forced-tight run: state list: translating on 1 workers (RAM guard) / warming stage libraries on 1 workers (RAM guard)
  • Explicit HOOKSHOT_SHADER_WORKERS=8 still wins over the guard (see #2725)

Made with Cursor

> [@yeetbot90](https://github.com/yeetbot90) opened this pull request on GitHub · 2026-11-12 09:30 UTC · [original](https://github.com/NotRexed/Hookshot/pull/2727) ## Summary - Add `prepare_ram_mb` and an opt-in `HOOKSHOT_PREPARE_RAM_GUARD` / `RX_VK_PREPARE_RAM_GUARD` that caps *auto* prepare worker counts by `(avail - reserve) / worker_peak_MB`. - Always apply a critical floor under ~2 GB available (2 workers) / ~1 GB (1 worker) so prepare does not thrash; explicit `HOOKSHOT_SHADER_WORKERS` still wins for A/B above that. - Tunables: `HOOKSHOT_PREPARE_WORKER_MB` (default 384, provisional), `HOOKSHOT_PREPARE_RESERVE_MB` / `HOOKSHOT_MEM_RESERVE_GB`. Documented in `docs/development.md`. Depends on #2725 (this branch is stacked on it). ## Test plan - [x] `python -I -B tests/test_prepare_pool_workers.py` / `test_prepare_cpus.py` - [x] CI: Python source checks green on Windows + Ubuntu (all four jobs). - [x] Rebuild tip DLL; `--prepare-shaders` with `HOOKSHOT_PREPARE_RAM_GUARD=1 HOOKSHOT_PREPARE_RESERVE_MB=10000 HOOKSHOT_PREPARE_WORKER_MB=2000` (+ `RX_VK_GPL=1`) - [x] AMD RX 9070 XT log: - `prepare resources ... RAM 14284 MB available / 31801 MB total, process 4792 MB (peak 7668), RAM guard on` then `preparing shaders on 2 workers (RAM guard, usable 24)` - later forced-tight run: `state list: translating on 1 workers (RAM guard)` / `warming stage libraries on 1 workers (RAM guard)` - [x] Explicit `HOOKSHOT_SHADER_WORKERS=8` still wins over the guard (see #2725) Made with [Cursor](https://cursor.com) <!-- github-sync:item:2727 -->
Centralize pool sizing in prepare_pool_workers so HOOKSHOT_SHADER_WORKERS /
RX_VK_PREPARE_WORKERS can A/B fewer threads when RAM is tight, without changing
the default half/usable/background sizes. Log a one-line CPU and RAM snapshot
at prepare start.

Co-authored-by: Cursor <[email protected]>
Cap auto-sized prepare pools by available RAM when HOOKSHOT_PREPARE_RAM_GUARD
is on, and always force a tiny pool under ~2 GB so a prepare does not thrash.
Explicit worker overrides still win for A/B.

Co-authored-by: Cursor <[email protected]>
test_prepare_stall's predict harness needed PreparePool / prepare_pool_workers /
prepare_resources_log after the override wiring. The pool-workers check stubs
prepare_ram_mb and compiles with _CRT_SECURE_NO_WARNINGS for MSVC getenv.

Co-authored-by: Cursor <[email protected]>
Author
Owner

@Joey-Magnus reviewed on GitHub · 2026-11-12 14:34 UTC · original

This branch is #2725 plus 446dab5e, and #2728 and #2729 both contain it unchanged, each with its own copy of the test-fix commit on top. Merging them in order would conflict, so I'd close this and keep one PR for the worker counts. My review of the code is on #2729.

The point that belongs to this commit: the RAM guard is described as opt-in, but the "RAM low"/"RAM critical" cap (vk_progcache.cpp:800-809 on #2729) runs for everyone. With under 2 GB available at the moment a pool starts, translation and pipeline builds drop to 2 workers for the whole run, because available RAM is read once and never again. That is a default change for 8 GB laptops and similar machines, with no measurement on one yet, so it needs a maintainer's yes. The code comment also says only the <1 GB floor overrides an explicit HOOKSHOT_SHADER_WORKERS, but the code applies the 2 GB cap to an override too.

> [@Joey-Magnus](https://github.com/Joey-Magnus) reviewed on GitHub · 2026-11-12 14:34 UTC · [original](https://github.com/NotRexed/Hookshot/pull/2727#pullrequestreview-5876240766) This branch is #2725 plus 446dab5e, and #2728 and #2729 both contain it unchanged, each with its own copy of the test-fix commit on top. Merging them in order would conflict, so I'd close this and keep one PR for the worker counts. My review of the code is on #2729. The point that belongs to this commit: the RAM guard is described as opt-in, but the "RAM low"/"RAM critical" cap (vk_progcache.cpp:800-809 on #2729) runs for everyone. With under 2 GB available at the moment a pool starts, translation and pipeline builds drop to 2 workers for the whole run, because available RAM is read once and never again. That is a default change for 8 GB laptops and similar machines, with no measurement on one yet, so it needs a maintainer's yes. The code comment also says only the <1 GB floor overrides an explicit `HOOKSHOT_SHADER_WORKERS`, but the code applies the 2 GB cap to an override too. <!-- github-sync:r:5876240766 -->
Commenting is not possible because the repository is archived.
No description provided.