perf(gpu): FastTls, lock-free keep_ref, O(1) SAME_ENTRIES, MISS_GAPS cache, and 8MiB list stack #4838

Closed
github-bot wants to merge 3 commits from github-bot/gh-4837 into main AGit
Owner

@⁠Pototoooo on GitHub · 2026-12-01 10:46 UTC · original
Pototoooo:perf/low-frame-optimizations → main · +634 −167 · 20 files · 3 commits · closed without merging

Summary

This PR bundles five rounds of CPU/low-frame optimizations and community-requested fixes targeting 1% low / 0.1% low frame times and list-translation overhead on Windows (x86_64-pc-windows-gnu):

1. Native Win32 FastTls (crates/victory-gpu/src/fast_tls.rs)

  • On x86_64-pc-windows-gnu, std::thread_local! emits a SeqCst mfence + guard::windows::enable() on every access, accounting for ~29% of victory-list-* worker CPU time in profiles.
  • Added a native Win32 TlsAlloc/TlsGetValue/TlsSetValue wrapper (FastTls<T>) with FlsAlloc thread-exit destructor cleanup and migrated the hot thread-locals across draw.rs, shadow.rs, descriptor/host.rs, descriptor.rs, residency.rs, facewatch.rs, list.rs, host.rs, host/send.rs, heap_marks.rs, and queue/behind.rs.
  • Cuts atomic::fence + guard::windows::enable samples in victory-list-* by 85–86%.

2. Descriptor & Draw Hot-Path Optimizations

  • Lock-free HostHeap::kept_raw mirror (descriptor/host.rs): eliminates mutex contention on keep, keep_ref, take_kept, and slots_showing.
  • O(1) SAME_ENTRIES cache (draw.rs): replaces linear Vec scan with a 512-slot epoch-tagged direct-mapped cache.
  • sampled::HotLookup snapshot + VICTORY_DUE_INDEX on by default (sampled.rs, descriptor/host.rs): hoists OnceLock + Acquire loads out of Due::ordered and collect_due_and_census.
  • Texture-pass early-out (draw.rs): removes the due_index() gate on PASS_FRAME_NANOS >= max_cap and adds a byte-budget early-out.
  • Added a 16-slot per-thread FastTls MISS_GAPS interval cache in shadow::lookup_buffer, validated by BUFFERS_CHANGED, computing sound buffer-free [gap_lo, gap_hi) intervals via find_miss_gap.
  • Added buffers_no_bump() for None -> Some(shadow) first-touch population in lookup_buffer so populating a shadow copy does not invalidate FOUND or MISS_GAPS across all worker threads.

4. Community Fixes & Launcher Defaults

  • Fix #4812 (list/thin.rs): set .stack_size(8 * 1024 * 1024) on victory-list-* worker threads to prevent 2 MiB default stack overflows.
  • Related to #4752 (shadow.rs): added optional VICTORY_SEND_GAP (default 0 = off) to coalesce nearby changed runs in Shadow::take.
  • Launcher defaults (apps/victory/src/play.rs): enabled VICTORY_SEND_BESIDE=1, VICTORY_LATE_WAIT_LISTS=384, VICTORY_DUE_INDEX=1, and the four #4816 switches (VICTORY_CARD_STEPS_LEARN=1, VICTORY_LATE_FILLS=1, VICTORY_SEND_FREE_FIRST=1, VICTORY_SWEEP_AHEAD=1).
  • Benchmark script (scripts/bench.ps1): updated frame-line regex to match both without a host pipeline and draws or dispatches.

Benchmark Results

Controlled stationary A/B runs (scripts/bench.ps1, -Warmup 30 -Seconds 45 -CaptureEvery 0, same checkpoint, ~9,500 draws/frame, RTX 5070 12 GB + Ryzen 5 9600X, thin-LTO diag build):

Build Median / Mean FPS 1% Low (p99) 0.1% Low (p99.9) Copying Back Boot to World Crashes / Refused
Baseline (5fabb46e) 14.6 fps (68.4 ms) 9.9 fps (101.1 ms) 8.5 fps (117.8 ms) 23.9 ms ~61 s 0 / 0
Waves 1–4 (bd0b5a96) 17.0 fps (59.0 ms) 11.4 fps (87.9 ms) 9.1 fps (109.3 ms) 18.6 ms ~61 s 0 / 0
Wave 4 + #4816 switches 17.2 fps (58.0 ms) 12.4 fps (80.5 ms) 7.0 fps (142.6 ms) 14.4 ms 61 s 0 / 0
Full PR (d5230f51) 16.6 med / 16.9 mean 11.5 fps (87.0 ms) 9.8 fps (102.3 ms) 13.0–16.2 ms 47 s 0 / 0

Testing

  • cargo test -p victory-gpu --lib -- wave5_tests max_size_tracks fast_tls::tests sampled::tests due_buckets keep_ref_skips_clone: 16 passed, 0 failed.
  • Production fat-LTO cargo build --release -p victory (linked with lld) verified and smoke-tested live.
**@⁠Pototoooo** on GitHub · 2026-12-01 10:46 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4837) `Pototoooo:perf/low-frame-optimizations` → `main` · +634 −167 · 20 files · 3 commits · closed without merging ## Summary This PR bundles five rounds of CPU/low-frame optimizations and community-requested fixes targeting `1% low` / `0.1% low` frame times and list-translation overhead on Windows (`x86_64-pc-windows-gnu`): ### 1. Native Win32 `FastTls` (`crates/victory-gpu/src/fast_tls.rs`) - On `x86_64-pc-windows-gnu`, `std::thread_local!` emits a `SeqCst` `mfence` + `guard::windows::enable()` on every access, accounting for ~29% of `victory-list-*` worker CPU time in profiles. - Added a native Win32 `TlsAlloc`/`TlsGetValue`/`TlsSetValue` wrapper (`FastTls<T>`) with `FlsAlloc` thread-exit destructor cleanup and migrated the hot thread-locals across `draw.rs`, `shadow.rs`, `descriptor/host.rs`, `descriptor.rs`, `residency.rs`, `facewatch.rs`, `list.rs`, `host.rs`, `host/send.rs`, `heap_marks.rs`, and `queue/behind.rs`. - Cuts `atomic::fence` + `guard::windows::enable` samples in `victory-list-*` by 85–86%. ### 2. Descriptor & Draw Hot-Path Optimizations - **Lock-free `HostHeap::kept_raw` mirror** (`descriptor/host.rs`): eliminates mutex contention on `keep`, `keep_ref`, `take_kept`, and `slots_showing`. - **O(1) `SAME_ENTRIES` cache** (`draw.rs`): replaces linear `Vec` scan with a 512-slot epoch-tagged direct-mapped cache. - **`sampled::HotLookup` snapshot + `VICTORY_DUE_INDEX` on by default** (`sampled.rs`, `descriptor/host.rs`): hoists `OnceLock` + `Acquire` loads out of `Due::ordered` and `collect_due_and_census`. - **Texture-pass early-out** (`draw.rs`): removes the `due_index()` gate on `PASS_FRAME_NANOS >= max_cap` and adds a byte-budget early-out. ### 3. Buffer Lookup `MISS_GAPS` Cache & No-Bump First Touch (related to #4818) - Added a 16-slot per-thread `FastTls` `MISS_GAPS` interval cache in `shadow::lookup_buffer`, validated by `BUFFERS_CHANGED`, computing sound buffer-free `[gap_lo, gap_hi)` intervals via `find_miss_gap`. - Added `buffers_no_bump()` for `None -> Some(shadow)` first-touch population in `lookup_buffer` so populating a shadow copy does not invalidate `FOUND` or `MISS_GAPS` across all worker threads. ### 4. Community Fixes & Launcher Defaults - **Fix #4812** (`list/thin.rs`): set `.stack_size(8 * 1024 * 1024)` on `victory-list-*` worker threads to prevent 2 MiB default stack overflows. - **Related to #4752** (`shadow.rs`): added optional `VICTORY_SEND_GAP` (default `0` = off) to coalesce nearby changed runs in `Shadow::take`. - **Launcher defaults** (`apps/victory/src/play.rs`): enabled `VICTORY_SEND_BESIDE=1`, `VICTORY_LATE_WAIT_LISTS=384`, `VICTORY_DUE_INDEX=1`, and the four #4816 switches (`VICTORY_CARD_STEPS_LEARN=1`, `VICTORY_LATE_FILLS=1`, `VICTORY_SEND_FREE_FIRST=1`, `VICTORY_SWEEP_AHEAD=1`). - **Benchmark script** (`scripts/bench.ps1`): updated frame-line regex to match both `without a host pipeline` and `draws or dispatches`. ## Benchmark Results Controlled stationary A/B runs (`scripts/bench.ps1`, `-Warmup 30 -Seconds 45 -CaptureEvery 0`, same checkpoint, ~9,500 draws/frame, RTX 5070 12 GB + Ryzen 5 9600X, thin-LTO `diag` build): | Build | Median / Mean FPS | 1% Low (p99) | 0.1% Low (p99.9) | Copying Back | Boot to World | Crashes / Refused | |---|---|---|---|---|---|---| | Baseline (`5fabb46e`) | 14.6 fps (68.4 ms) | 9.9 fps (101.1 ms) | 8.5 fps (117.8 ms) | 23.9 ms | ~61 s | 0 / 0 | | Waves 1–4 (`bd0b5a96`) | 17.0 fps (59.0 ms) | 11.4 fps (87.9 ms) | 9.1 fps (109.3 ms) | 18.6 ms | ~61 s | 0 / 0 | | Wave 4 + #4816 switches | **17.2 fps** (58.0 ms) | **12.4 fps (80.5 ms)** | 7.0 fps (142.6 ms) | 14.4 ms | 61 s | 0 / 0 | | Full PR (`d5230f51`) | 16.6 med / 16.9 mean | **11.5 fps (87.0 ms)** | **9.8 fps (102.3 ms)** | 13.0–16.2 ms | **47 s** | **0 / 0** | ## Testing - `cargo test -p victory-gpu --lib -- wave5_tests max_size_tracks fast_tls::tests sampled::tests due_buckets keep_ref_skips_clone`: **16 passed, 0 failed**. - Production fat-LTO `cargo build --release -p victory` (linked with `lld`) verified and smoke-tested live.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 10:47:53 +00:00
github-bot force-pushed github-bot/gh-4837 from d4728864fa to 06dbed219f 2026-12-01 12:32:12 +00:00 Compare
github-bot force-pushed github-bot/gh-4837 from 06dbed219f to 81d7cc3d96 2026-12-01 13:16:05 +00:00 Compare
github-bot closed this pull request 2026-12-01 18:36:25 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:30 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:30 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4837#issuecomment-7321068229) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
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
github/trustno1-coder--VIctory-NVIDIA!4838
No description provided.