BUG:victory-gpu: Placed-view shape cap (2^22) causes unbounded VIEWS leak & multi-second write-lock freezes (Root cause, verified fix on my fork + Agent prompt) #333

Open
opened 2026-11-30 06:55:31 +00:00 by 3sssm0keee · 2 comments
3sssm0keee commented 2026-11-30 06:55:31 +00:00 (Migrated from github.com)
Contributor

Imported from PastiiJay/klbf-lab. Originally posted by 3sssm0keee on 2026-11-30T06:55:31Z.



Context & Note to the Team

Hi team,

I've been debugging and tuning a local fork/branch based on VIctory on my own Windows setup (AMD RX 9070 XT 16 GB, 32 GB RAM). During extended gameplay sessions (30–55 minutes), I ran into two severe issues that turned out to share a single root cause in victory-gpu/src/descriptor.rs:

  1. Runaway memory growth — process private commit steadily climbed past 40 GiB and hit 48+ GiB over a 54-minute run.
  2. Recurring, exponentially worsening multi-second freezes (1.5 s → 3.7 s → 9.3 s), each coinciding with a sudden multi-GiB private commit jump (+1 GiB / +2 GiB / +4.25 GiB) and a sharp drop in working set, followed by heavy late-session FPS degradation.

Because the relevant code in descriptor.rs appears to be shared across VIctory-based branches, I've already implemented and long-run verified a fix in my local environment. I'm sharing the full breakdown, before/after telemetry, and a self-contained prompt at the bottom that you can hand directly to a coding agent to audit your branch and adapt the fix—hope this helps!


What Was Happening (Root Cause)

Profiling VIEWS read/write lock contention and table growth across a 54m 10s run closed the loop:

  1. The placed-view shapes table saturates early (2^22 = 4,194,304 cap)

    • Inline placed-view encoding stores the low 40 address bits plus a 22-bit shape ID.
    • Each shape key bundles the read/write flag, all 14 resource words (R0–R13, including alignment/trailing padding words R1 and R13), and all 14 non-address view words (D0–D9, D12–D15).
    • In my run, shapes hit its 4,194,304 ceiling at 08:28 (when the general VIEWS table only had 22,860 entries).
  2. Saturation triggers an unreclaimed per-address leak into views.list

    • Once shapes is full, new placed views fall back to inserting full records (~136 B/row + index tree) into the general VIEWS table (views.list) keyed per address.
    • Because placed views do not carry a regular resource handle, forget(resource) never reclaims them. By 54:10, views.list had ballooned to 37,495,611 entries.
  3. Contiguous Vec doubling under the global write lock causes the multi-second freezes

    • views.list is backed by a single contiguous Vec guarded by the global VIEWS: RwLock<Views>.
    • Whenever a single insertion hits a power-of-two capacity boundary, the writer allocates and copies gigabytes of entries while holding VIEWS.write(), blocking every descriptor mirroring/recording thread:
Run Time VIEWS.write() Hold Reader Blocked Present Interval Private Commit Working Set
14:55 1.497 s 1.496 s 1.537 s 34.48 → 35.48 GiB —
23:20 3.727 s 3.538 s 3.873 s 38.16 → 40.18 GiB —
45:22 9.125 s — 9.305 s 44.05 → 48.30 GiB (+4.250 GiB table cap) 12.04 → 3.05 GiB

How I Fixed It in My Environment

  1. Lossless orthogonal component-dictionary encoding (Kind 3) — Instead of indexing the full Cartesian product into one 22-bit shape table, placed views are split losslessly into 4 small component dictionaries (resource_prefix, descriptor, pad_a for R1, pad_b for R13) plus an extended 4-tuple fallback, with the low 26 address bits stored inline. Every original bit is preserved without masking.
  2. Fixed-size paged storage — Replaced the contiguous Vec backing for views.list, legacy shapes, and the new dictionaries with two-level paged slabs (1,024 rows/page, 256 pages/directory group; 136 KiB/page for views.list). Growth allocates a single small page without ever relocating existing rows under VIEWS.write().

Results in My Environment (54m 10s Baseline vs. 50m 05s Patched)

Same hardware, same launch flags, default 4 MiB buffer window:

Metric Before After Delta
General VIEWS entries (end of run) 37,495,611 8,818 −99.98%
Placed-view fallbacks to general table Unbounded (after 08:28) 0 Eliminated
Private commit median (45–50 min) 48.90 GiB 29.60 GiB −19.30 GiB
Full-run private commit peak 48.30+ GiB 31.33 GiB (end: 29.76 GiB) Below 32 GB RAM wall
VIEWS write-lock stalls ≥ 50 ms 3 (1.50 s, 3.73 s, 9.13 s) 0 Eliminated
Frame stalls > 1 s after startup (03:30–50:05) Recurring multi-second freezes 0 Eliminated
Median FPS (20–30 min, 6k–8k draws/frame; n=17 vs 29) 17.9 FPS 24.6 FPS +37.4%
Frame prep time (20–30 min, 6k–8k draws/frame) 34.4 ms/frame 21.4 ms/frame −37.8%

Unit tests (victory-gpu): 471 passed, 0 failed (including 100,000 randomized bit-exact round-trips for the new encoding and paged-storage stability/concurrency tests).


Prompt for Coding Agents (Audit & Port to Your Branch)

If your team uses a coding agent (Codex, Claude Code, etc.), you can paste the prompt below directly to have it check whether your branch is affected and implement an adapted version of this fix:

Task: Audit this VIctory-based repository for the `victory-gpu` placed-view `shapes` saturation leak and `VIEWS` write-lock reallocation freeze bug, and implement a verified fix adapted to the current codebase.

### Context & Failure Signature
In VIctory-based branches, long gameplay sessions can hit runaway private commit growth (40–48+ GiB) and recurring multi-second freezes (1.5s -> 3.7s -> 9.3s) caused by `crates/victory-gpu/src/descriptor.rs`:
1. Inline placed-view encoding uses a 22-bit shape index (`4,194,304` cap) over the full Cartesian product of read/write flag, resource words `R0–R13` (including padding words), and non-address view words `D0–D15`. It saturates in ~8.5 minutes of gameplay.
2. After saturation, new placed views fall back to per-address insertions into the general `VIEWS` table (`views.list`). Because placed views have no resource handle, `forget(resource)` never reclaims them, causing unbounded memory growth (observed 37.5M entries in 54 minutes).
3. `views.list` is backed by a single contiguous `Vec` guarded by global `VIEWS: RwLock<Views>`. Power-of-two reallocations allocate and copy gigabytes while holding `VIEWS.write()`, stalling all descriptor mirroring and recording threads.

### Phase 1: Read-Only Investigation (Verify Before Editing)
Inspect the codebase and report exact file paths and line numbers for:
1. The descriptor-view global `VIEWS: RwLock<Views>` in `descriptor.rs` (do NOT confuse with similarly named symbols in `inplace.rs` or `watch.rs`).
2. Placed-view inline encoding/decoding (`placed_words`, `words_for_shape`, `placed_of` or equivalents): verify whether the 22-bit cap and monolithic shape key exist, and document the exact bit/word layout of `R0–R13` and `D0–D15`.
3. The shape-saturation fallback path and `forget(resource)` cleanup logic, confirming whether fallback placed views are permanently retained.
4. Whether `views.list` and `shapes` use contiguous `Vec` storage, plus a complete list of `VIEWS` read/write lock acquisition sites and lock ordering relative to per-slot `Made` locks.
5. Every site in the workspace that dispatches or branches on view encoding kind tags (Kind 0/1/2), specifically checking descriptor mirroring, copy-wait branches, and invalidation paths so no site misses a newly introduced Kind 3.

### Phase 2: Implement the Fix (If Confirmed Affected)
Adapt the following architecture to this repository without breaking existing semantics or lock ordering:

1. **Lossless Orthogonal Component-Dictionary Encoding (Kind 3):**
   - Preserve every bit of `R0–R13` and `D0–D15` losslessly (do NOT drop or mask padding words `R1`/`R13`).
   - Decompose placed views into 4 independent dictionaries + 1 extended tuple dictionary:
     * `resource_prefix` (64 B/row): `R0`, `R2–R12`, high 38 address bits, read/write flag.
     * `descriptor` (56 B/row): `D0–D9`, `D12–D15`.
     * `pad_a` (4 B/row): full 32-bit `R1`.
     * `pad_b***
<!-- greyfinch-sync:PastiiJay/klbf-lab:issue:6690706975 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/issues/333). Originally posted by [3sssm0keee](https://github.com/3sssm0keee) on 2026-11-30T06:55:31Z. --- --- ### Context & Note to the Team Hi team, I've been debugging and tuning a local fork/branch based on **VIctory** on my own Windows setup (AMD RX 9070 XT 16 GB, 32 GB RAM). During extended gameplay sessions (30–55 minutes), I ran into two severe issues that turned out to share a single root cause in `victory-gpu/src/descriptor.rs`: 1. **Runaway memory growth** — process private commit steadily climbed past 40 GiB and hit **48+ GiB** over a 54-minute run. 2. **Recurring, exponentially worsening multi-second freezes** (`1.5 s` → `3.7 s` → `9.3 s`), each coinciding with a sudden multi-GiB private commit jump (`+1 GiB` / `+2 GiB` / `+4.25 GiB`) and a sharp drop in working set, followed by heavy late-session FPS degradation. Because the relevant code in `descriptor.rs` appears to be shared across VIctory-based branches, I've already implemented and long-run verified a fix in my local environment. I'm sharing the full breakdown, before/after telemetry, and a self-contained prompt at the bottom that you can hand directly to a coding agent to audit your branch and adapt the fix—hope this helps! --- ### What Was Happening (Root Cause) Profiling `VIEWS` read/write lock contention and table growth across a 54m 10s run closed the loop: 1. **The placed-view `shapes` table saturates early (`2^22` = 4,194,304 cap)** - Inline placed-view encoding stores the low 40 address bits plus a 22-bit shape ID. - Each shape key bundles the read/write flag, all 14 resource words (`R0–R13`, including alignment/trailing padding words `R1` and `R13`), and all 14 non-address view words (`D0–D9`, `D12–D15`). - In my run, `shapes` hit its **4,194,304** ceiling at **08:28** (when the general `VIEWS` table only had **22,860** entries). 2. **Saturation triggers an unreclaimed per-address leak into `views.list`** - Once `shapes` is full, new placed views fall back to inserting full records (~136 B/row + index tree) into the general `VIEWS` table (`views.list`) keyed per address. - Because placed views do not carry a regular resource handle, `forget(resource)` never reclaims them. By **54:10**, `views.list` had ballooned to **37,495,611 entries**. 3. **Contiguous `Vec` doubling under the global write lock causes the multi-second freezes** - `views.list` is backed by a single contiguous `Vec` guarded by the global `VIEWS: RwLock<Views>`. - Whenever a single insertion hits a power-of-two capacity boundary, the writer allocates and copies gigabytes of entries while holding `VIEWS.write()`, blocking every descriptor mirroring/recording thread: | Run Time | `VIEWS.write()` Hold | Reader Blocked | Present Interval | Private Commit | Working Set | |---|---:|---:|---:|---:|---:| | 14:55 | 1.497 s | 1.496 s | 1.537 s | 34.48 → 35.48 GiB | — | | 23:20 | 3.727 s | 3.538 s | 3.873 s | 38.16 → 40.18 GiB | — | | 45:22 | 9.125 s | — | 9.305 s | 44.05 → 48.30 GiB (`+4.250 GiB` table cap) | 12.04 → 3.05 GiB | --- ### How I Fixed It in My Environment 1. **Lossless orthogonal component-dictionary encoding (Kind 3)** — Instead of indexing the full Cartesian product into one 22-bit shape table, placed views are split losslessly into 4 small component dictionaries (`resource_prefix`, `descriptor`, `pad_a` for `R1`, `pad_b` for `R13`) plus an `extended` 4-tuple fallback, with the low 26 address bits stored inline. Every original bit is preserved without masking. 2. **Fixed-size paged storage** — Replaced the contiguous `Vec` backing for `views.list`, legacy `shapes`, and the new dictionaries with two-level paged slabs (`1,024` rows/page, `256` pages/directory group; `136 KiB`/page for `views.list`). Growth allocates a single small page without ever relocating existing rows under `VIEWS.write()`. ### Results in My Environment (54m 10s Baseline vs. 50m 05s Patched) Same hardware, same launch flags, default 4 MiB buffer window: | Metric | Before | After | Delta | |---|---:|---:|---:| | General `VIEWS` entries (end of run) | 37,495,611 | **8,818** | **−99.98%** | | Placed-view fallbacks to general table | Unbounded (after 08:28) | **0** | Eliminated | | Private commit median (45–50 min) | 48.90 GiB | **29.60 GiB** | **−19.30 GiB** | | Full-run private commit peak | 48.30+ GiB | **31.33 GiB** (end: 29.76 GiB) | Below 32 GB RAM wall | | `VIEWS` write-lock stalls ≥ 50 ms | 3 (`1.50 s`, `3.73 s`, `9.13 s`) | **0** | Eliminated | | Frame stalls > 1 s after startup (`03:30–50:05`) | Recurring multi-second freezes | **0** | Eliminated | | Median FPS (`20–30 min`, `6k–8k` draws/frame; n=17 vs 29) | 17.9 FPS | **24.6 FPS** | **+37.4%** | | Frame prep time (`20–30 min`, `6k–8k` draws/frame) | 34.4 ms/frame | **21.4 ms/frame** | **−37.8%** | Unit tests (`victory-gpu`): **471 passed, 0 failed** (including 100,000 randomized bit-exact round-trips for the new encoding and paged-storage stability/concurrency tests). --- ### Prompt for Coding Agents (Audit & Port to Your Branch) If your team uses a coding agent (Codex, Claude Code, etc.), you can paste the prompt below directly to have it check whether your branch is affected and implement an adapted version of this fix: ```text Task: Audit this VIctory-based repository for the `victory-gpu` placed-view `shapes` saturation leak and `VIEWS` write-lock reallocation freeze bug, and implement a verified fix adapted to the current codebase. ### Context & Failure Signature In VIctory-based branches, long gameplay sessions can hit runaway private commit growth (40–48+ GiB) and recurring multi-second freezes (1.5s -> 3.7s -> 9.3s) caused by `crates/victory-gpu/src/descriptor.rs`: 1. Inline placed-view encoding uses a 22-bit shape index (`4,194,304` cap) over the full Cartesian product of read/write flag, resource words `R0–R13` (including padding words), and non-address view words `D0–D15`. It saturates in ~8.5 minutes of gameplay. 2. After saturation, new placed views fall back to per-address insertions into the general `VIEWS` table (`views.list`). Because placed views have no resource handle, `forget(resource)` never reclaims them, causing unbounded memory growth (observed 37.5M entries in 54 minutes). 3. `views.list` is backed by a single contiguous `Vec` guarded by global `VIEWS: RwLock<Views>`. Power-of-two reallocations allocate and copy gigabytes while holding `VIEWS.write()`, stalling all descriptor mirroring and recording threads. ### Phase 1: Read-Only Investigation (Verify Before Editing) Inspect the codebase and report exact file paths and line numbers for: 1. The descriptor-view global `VIEWS: RwLock<Views>` in `descriptor.rs` (do NOT confuse with similarly named symbols in `inplace.rs` or `watch.rs`). 2. Placed-view inline encoding/decoding (`placed_words`, `words_for_shape`, `placed_of` or equivalents): verify whether the 22-bit cap and monolithic shape key exist, and document the exact bit/word layout of `R0–R13` and `D0–D15`. 3. The shape-saturation fallback path and `forget(resource)` cleanup logic, confirming whether fallback placed views are permanently retained. 4. Whether `views.list` and `shapes` use contiguous `Vec` storage, plus a complete list of `VIEWS` read/write lock acquisition sites and lock ordering relative to per-slot `Made` locks. 5. Every site in the workspace that dispatches or branches on view encoding kind tags (Kind 0/1/2), specifically checking descriptor mirroring, copy-wait branches, and invalidation paths so no site misses a newly introduced Kind 3. ### Phase 2: Implement the Fix (If Confirmed Affected) Adapt the following architecture to this repository without breaking existing semantics or lock ordering: 1. **Lossless Orthogonal Component-Dictionary Encoding (Kind 3):** - Preserve every bit of `R0–R13` and `D0–D15` losslessly (do NOT drop or mask padding words `R1`/`R13`). - Decompose placed views into 4 independent dictionaries + 1 extended tuple dictionary: * `resource_prefix` (64 B/row): `R0`, `R2–R12`, high 38 address bits, read/write flag. * `descriptor` (56 B/row): `D0–D9`, `D12–D15`. * `pad_a` (4 B/row): full 32-bit `R1`. * `pad_b***
PastiiJay commented 2026-11-30 09:56:47 +00:00 (Migrated from github.com)
Author
Contributor

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-30T09:56:47Z.


Thanks for the detailed write-up, the analysis is spot on.

In KLBF Lab this is already handled on two sides:

  • the padding words are normalized before shapes are deduplicated, so the same view no longer creates a new shape (KLBF_PLACED_NORMAL, on by default; taken from VIctory-LITE f234022, which got it from trustno1-coder/VIctory-NVIDIA 4eead678 / 144aca0f)
  • owner-less views are capped at 1 million, oldest freed first (KLBF_OWNERLESS_VIEWS, since v26.11.10, after VIctory-NVIDIA 89fd9361)

With both, the shapes table stays far from the 2^22 cap: the "memory, more:" line in .17 logs shows around 100k shapes kept after 25 minutes, and 0 placed views in the general table.

If you still see the growth with KLBF Lab itself, please paste the "memory, more:" lines from your run log here (just those lines, the full log shows your Windows user name).

Your component-dictionary idea is interesting for cutting memory further, it's noted.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7274899996 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/issues/333#issuecomment-7274899996). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-30T09:56:47Z. --- Thanks for the detailed write-up, the analysis is spot on. In KLBF Lab this is already handled on two sides: - the padding words are normalized before shapes are deduplicated, so the same view no longer creates a new shape (`KLBF_PLACED_NORMAL`, on by default; taken from VIctory-LITE f234022, which got it from trustno1-coder/VIctory-NVIDIA 4eead678 / 144aca0f) - owner-less views are capped at 1 million, oldest freed first (`KLBF_OWNERLESS_VIEWS`, since v26.11.10, after VIctory-NVIDIA 89fd9361) With both, the shapes table stays far from the 2^22 cap: the "memory, more:" line in .17 logs shows around 100k shapes kept after 25 minutes, and 0 placed views in the general table. If you still see the growth with **KLBF Lab** itself, please paste the "memory, more:" lines from your run log here (just those lines, the full log shows your Windows user name). Your component-dictionary idea is interesting for cutting memory further, it's noted.
3sssm0keee commented 2026-11-30 10:27:38 +00:00 (Migrated from github.com)
Author
Contributor

Imported from PastiiJay/klbf-lab. Originally posted by 3sssm0keee on 2026-11-30T10:27:38Z.


Thanks buddy, hope team could get it done for pc players!!!

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7275627761 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/issues/333#issuecomment-7275627761). Originally posted by [3sssm0keee](https://github.com/3sssm0keee) on 2026-11-30T10:27:38Z. --- Thanks buddy, hope team could get it done for pc players!!!
Sign in to join this conversation.
No labels
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.

Reference
PastiiJay/klbf-lab#333
No description provided.