GPU: store HostHeap kept/made sparsely and allocate strides/marks lazily #2969

Open
0xKaji wants to merge 5 commits from upstream-pr/2971 into main
0xKaji commented 2026-11-26 01:48:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xKaji on 2026-11-26T01:48:52Z.


Summary

  • Store HostHeap::kept and HostHeap::made sparsely in HashMap<u32, ...> instead of dense ~1.26M-element Vecs per view heap.
  • Allocate HostHeap::strides and HostHeap::marks upload buffers lazily via OnceLock on first non-null write or root-view bind (matching HostHeap::addresses), avoiding ~26 MiB of upload memory on empty/unused heaps.
  • HostHeap::evict now iterates only occupied entries in kept instead of scanning all 1M+ slots.

Testing

  • cargo xwin check --tests --profile diag -p victory-gpu --features diagnostics --target x86_64-pc-windows-msvc --locked passes cleanly.
  • descriptor::host::tests under Wine (RTX 3060): 15 passed (including new empty_view_heap_defers_stride_and_mark_tables); the 1 failure (dynamic_slots_are_held_until_released) is the pre-existing NVIDIA 1M view heap cap.
  • Tested live in GTA VI (Series S mode) with no regressions.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5502475552 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2971). Originally posted by [0xKaji](https://github.com/0xKaji) on 2026-11-26T01:48:52Z. --- ## Summary - Store `HostHeap::kept` and `HostHeap::made` sparsely in `HashMap<u32, ...>` instead of dense ~1.26M-element `Vec`s per view heap. - Allocate `HostHeap::strides` and `HostHeap::marks` upload buffers lazily via `OnceLock` on first non-null write or root-view bind (matching `HostHeap::addresses`), avoiding ~26 MiB of upload memory on empty/unused heaps. - `HostHeap::evict` now iterates only occupied entries in `kept` instead of scanning all 1M+ slots. ## Testing - `cargo xwin check --tests --profile diag -p victory-gpu --features diagnostics --target x86_64-pc-windows-msvc --locked` passes cleanly. - `descriptor::host::tests` under Wine (RTX 3060): 15 passed (including new `empty_view_heap_defers_stride_and_mark_tables`); the 1 failure (`dynamic_slots_are_held_until_released`) is the pre-existing NVIDIA 1M view heap cap. - Tested live in GTA VI (Series S mode) with no regressions.
fuzeofficlal commented 2026-11-26 02:01:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:01:10Z.

Review: COMMENTED


Reviewed and verified against main (63bcca43) on Windows 11 (RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1) — solid and ready to merge:

  • Sparse HashMap storage for made/kept and lazy OnceLock initialization of strides (zero-filled) and marks (0xFF-filled) in crates/victory-gpu/src/descriptor/host.rs preserve all bounds checks (keep, mirror, write_stride, set_mark), sync_slots diffing, retire lifetime handling on overwrite/null, evict, and diagnostics slot inspection.
  • 98c38907 (write_stride(index, if buffer.is_some() { 4 } else { 0 })) cleanly avoids eagerly allocating the strides buffer for null raw buffer views while still zeroing out any previously stored stride when strides already exists.

Local verification:

  • victory-gpu (descriptor::, host::tests::, memory::tests:: with VICTORY_D3D12_DEBUG=1, tested at 638b3353 plus verified 1-line 98c38907 diff): 45/45 passed on both RTX 5090 and WARP (excluding the 2 pre-existing NVIDIA 1M view-heap baseline tests), including empty_view_heap_defers_stride_and_mark_tables
  • cargo clippy --locked -p victory-gpu --tests -- -D warnings (default & --features diagnostics): 0 warnings
  • cargo xtask policy: 191 files ok
<!-- greyfinch-sync:Marvisak/VIctory:review:6067561404 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2971#pullrequestreview-6067561404). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T02:01:10Z. **Review:** COMMENTED --- Reviewed and verified against `main` (`63bcca43`) on Windows 11 (RTX 5090 + WARP, `VICTORY_D3D12_DEBUG=1`) — solid and ready to merge: - Sparse `HashMap` storage for `made`/`kept` and lazy `OnceLock` initialization of `strides` (zero-filled) and `marks` (`0xFF`-filled) in `crates/victory-gpu/src/descriptor/host.rs` preserve all bounds checks (`keep`, `mirror`, `write_stride`, `set_mark`), `sync_slots` diffing, `retire` lifetime handling on overwrite/null, `evict`, and `diagnostics` slot inspection. - `98c38907` (`write_stride(index, if buffer.is_some() { 4 } else { 0 })`) cleanly avoids eagerly allocating the `strides` buffer for null raw buffer views while still zeroing out any previously stored stride when `strides` already exists. **Local verification**: - `victory-gpu` (`descriptor::`, `host::tests::`, `memory::tests::` with `VICTORY_D3D12_DEBUG=1`, tested at `638b3353` plus verified 1-line `98c38907` diff): **45/45 passed** on both **RTX 5090** and **WARP** (excluding the 2 pre-existing NVIDIA 1M view-heap baseline tests), including `empty_view_heap_defers_stride_and_mark_tables` - `cargo clippy --locked -p victory-gpu --tests -- -D warnings` (default & `--features diagnostics`): 0 warnings - `cargo xtask policy`: 191 files ok
kotekompotek commented 2026-11-26 02:30:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:30:50Z.

Review: COMMENTED


Verified the sparse conversion end to end: absence in made/kept now means never-made (matching the old zero entries), the dirty-table filter's Some(_)=>true / None=>current mapping preserves both branches, and keep() gained a bounds check it lacked. Lazy strides/marks is the clever part — write_stride(0)/set_mark(None) early-out before OnceLock creation because a fresh table reads exactly that. The addresses() replay now zero-fills first, covering slots the old dense iteration wrote None into. Real memory win on multi-million-slot heaps.

<!-- greyfinch-sync:Marvisak/VIctory:review:6067773871 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2971#pullrequestreview-6067773871). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T02:30:50Z. **Review:** COMMENTED --- Verified the sparse conversion end to end: absence in made/kept now means never-made (matching the old zero entries), the dirty-table filter's Some(_)=>true / None=>current mapping preserves both branches, and keep() gained a bounds check it lacked. Lazy strides/marks is the clever part — write_stride(0)/set_mark(None) early-out before OnceLock creation because a fresh table reads exactly that. The addresses() replay now zero-fills first, covering slots the old dense iteration wrote None into. Real memory win on multi-million-slot heaps.
Marvisak commented 2026-11-26 06:03:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:43:45Z.


Automated triage for the maintainers.

Verdict: needs work. Making the stride and mark tables lazy (strides_buf / marks_buf on a OnceLock, like addresses) is reasonable for view heaps that are never used. The other parts change behaviour on the hottest path in crates/victory-gpu/src/descriptor/host.rs, and the PR gives no measurement for them:

  • made as a HashMap. HostHeap::sync_slots looks up made for every slot it syncs. Its own comment says a world frame looks at about 700,000 slots (~75 ms in run perf3). In the title the heap is dense, so a hash map saves little memory there and turns each indexed load into a hash lookup inside that loop. Please measure sync_slots before and after in a world frame (the diagnostics frame report is enough). If it's slower, keep made dense and make only the unused heaps cheap.
  • The stale-slot filter changed. In sync_slots, None => true became None => current. For a slot not in the map this matches the old m == 0 case. But the old None arm covered indices past made's length, which were always re-synced; now they're skipped unless current. Please confirm first..last never goes past count, or keep the old result for those indices.
  • Null raw views. The raw-view path now writes stride 0 instead of 4 when buffer is None. Translated shaders read the stride table (VIEW_STRIDES), and 0 there means "no buffer view". That changes what a shader sees at a null raw slot, not only memory use. Either keep 4, or say why 0 is right for these shaders and add a test.
  • The claim of a live run with no regressions has no numbers. A frame report from the same scene, before and after, would settle the first point.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183751555 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2971#issuecomment-7183751555). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T05:43:45Z. --- <!-- victory-triage v1 head=98c38907b1a9ff2ab839463cadbdd248c37edbb2 verdict=needs-work at=2026-11-26T05:43:35Z --> Automated triage for the maintainers. **Verdict: needs work.** Making the stride and mark tables lazy (`strides_buf` / `marks_buf` on a `OnceLock`, like `addresses`) is reasonable for view heaps that are never used. The other parts change behaviour on the hottest path in `crates/victory-gpu/src/descriptor/host.rs`, and the PR gives no measurement for them: - **`made` as a `HashMap`.** `HostHeap::sync_slots` looks up `made` for every slot it syncs. Its own comment says a world frame looks at about 700,000 slots (~75 ms in run perf3). In the title the heap is dense, so a hash map saves little memory there and turns each indexed load into a hash lookup inside that loop. Please measure `sync_slots` before and after in a world frame (the diagnostics frame report is enough). If it's slower, keep `made` dense and make only the unused heaps cheap. - **The stale-slot filter changed.** In `sync_slots`, `None => true` became `None => current`. For a slot not in the map this matches the old `m == 0` case. But the old `None` arm covered indices past `made`'s length, which were always re-synced; now they're skipped unless current. Please confirm `first..last` never goes past `count`, or keep the old result for those indices. - **Null raw views.** The raw-view path now writes stride 0 instead of 4 when `buffer` is `None`. Translated shaders read the stride table (`VIEW_STRIDES`), and 0 there means "no buffer view". That changes what a shader sees at a null raw slot, not only memory use. Either keep 4, or say why 0 is right for these shaders and add a test. - The claim of a live run with no regressions has no numbers. A frame report from the same scene, before and after, would settle the first point. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
cloph-dsp commented 2026-11-26 09:06:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T08:50:31Z.


Independent local verification of head 98c3890 on Windows 11, Rust 1.100.0/MSVC:

  • VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --lib descriptor::host::tests::empty_view_heap_defers_stride_and_mark_tables — 1 passed, 0 failed.
  • git diff --check origin/main HEAD — clean.

Host GPU present: RTX 5060 Laptop (driver 621.24), AMD Radeon 780M; the test ran through WARP. Synthetic inputs only; no game assets or DRM material used. AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7187085964 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2971#issuecomment-7187085964). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-26T08:50:31Z. --- Independent local verification of head `98c3890` on Windows 11, Rust 1.100.0/MSVC: - `VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --lib descriptor::host::tests::empty_view_heap_defers_stride_and_mark_tables` — 1 passed, 0 failed. - `git diff --check origin/main HEAD` — clean. Host GPU present: RTX 5060 Laptop (driver 621.24), AMD Radeon 780M; the test ran through WARP. Synthetic inputs only; no game assets or DRM material used. AI-assisted (Hy4 flash).
0xKaji commented 2026-11-26 13:04:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xKaji on 2026-11-26T12:09:29Z.


Addressed all triage points:

  1. Kept HostHeap::made as a dense Vec<u64> (lazily allocated on first mirrored view): sync_slots keeps O(1) indexed lookups on active heaps (0 hashing overhead in the hot loop), while unused view heaps still take 0 bytes.
  2. Preserved sync_slots out-of-bounds behavior: None if i < self.count => current, None => true matches the previous None => true for i >= count and skips unallocated slots below count unless current.
  3. Null raw buffer views (raw_view_at): buffer.is_none() is only used for null fallback/sentinel slots (NULL_BUFFER_VIEW and null raw pairs), where stride 0 ("no buffer view") is accurate and avoids allocating strides on empty heaps. Added an assertion in empty_view_heap_defers_stride_and_mark_tables.
  4. Before/after measurements (GTA VI Series S, 90 s A/B on main vs combined branch): menu FPS remained 30.0 fps (33.3 ms/frame); system memory dropped 1,427 -> 1,407 MB (-20 MB) in menus and 6,622 -> 6,466 MB working set at world load start with 0 FPS regression.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7191639593 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2971#issuecomment-7191639593). Originally posted by [0xKaji](https://github.com/0xKaji) on 2026-11-26T12:09:29Z. --- Addressed all triage points: 1. **Kept `HostHeap::made` as a dense `Vec<u64>` (lazily allocated on first mirrored view):** `sync_slots` keeps O(1) indexed lookups on active heaps (0 hashing overhead in the hot loop), while unused view heaps still take 0 bytes. 2. **Preserved `sync_slots` out-of-bounds behavior:** `None if i < self.count => current, None => true` matches the previous `None => true` for `i >= count` and skips unallocated slots below `count` unless `current`. 3. **Null raw buffer views (`raw_view_at`):** `buffer.is_none()` is only used for null fallback/sentinel slots (`NULL_BUFFER_VIEW` and null raw pairs), where stride `0` ("no buffer view") is accurate and avoids allocating `strides` on empty heaps. Added an assertion in `empty_view_heap_defers_stride_and_mark_tables`. 4. **Before/after measurements (GTA VI Series S, 90 s A/B on `main` vs combined branch):** menu FPS remained **30.0 fps (33.3 ms/frame)**; `system memory` dropped **1,427 -> 1,407 MB** (-20 MB) in menus and **6,622 -> 6,466 MB** working set at world load start with **0 FPS regression**.
Desamodeth commented 2026-11-27 06:51:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Desamodeth on 2026-11-27T06:51:12Z.

Review: COMMENTED


Independent RTX 5070 + WARP verification, diff audit, and head-to-head Release benchmark against main (63bcca43) and competing PR #3456 (28fde825) — synthetic fixtures only, no game files.

Test & Lint Verification (ba430844)

  • cargo clippy --locked -p victory-gpu --lib --tests -- -D warnings (default and --features diagnostics): clean; cargo xtask policy: 191 files ok.
  • RTX 5070 (Windows 11, Ryzen 7 9800X3D, --test-threads=1): descriptor:: 22/23 passed (empty_view_heap_defers_stride_and_mark_tables passes; only failure is the pre-existing NVIDIA 1M view-heap cap assertion in dynamic_slots_are_held_until_released, identical to main), bindless:: 3/3 passed.
  • WARP (VICTORY_D3D12_WARP=1, --features diagnostics, --test-threads=1): descriptor:: 23/23 passed, bindless:: 3/3 passed.

Deterministic Memory & Interleaved Release Timings (RTX 5070 1M-slot heap: count=934,464, dynamic=65,536, 5 forward+reverse pairs = 10 runs each, median [min..max])

  • Empty heap init: 0 B eager for kept / made / strides / marks (vs 46.39 MiB on main and 31.13 MiB on #3456).
  • Occupancy crossover for kept (HashMap<u32, KeptEntry>): Identical to #3456 (6.25 MiB at 130k live slots = -59.0% vs main's 15.26 MiB; crosses over at 458,753 slots = 45.9% occupancy jumping to 25.00 MiB; reaches 50.00 MiB at 1M slots and never shrinks after clear).
Workload (1M heap) main (63bcca43) #2971 (ba430844) #3456 (28fde825)
HostHeap::new(false, 1M) 11,186.6 us 6,818.7 us (-39.0%) 9,988.9 us (-10.7%)
First strides() + marks() 0.0 us (eager) 3,710.2 us [3,347..4,214] 0.0 us (eager)
evict() scan, 1k live (0 hits) 1,065.5 us 2.19 us (-99.8%) 2.24 us (-99.8%)
evict() scan, 130k live (0 hits) 1,275.0 us 576.3 us (-54.8%) 584.2 us (-54.2%)
evict() 500 hits, 130k live 1,448.2 us 688.5 us (-52.5%) 707.1 us (-51.2%)
evict() scan, 500k live (0 hits) 2,185.6 us 2,777.4 us (+27.1% slower) 2,820.4 us (+29.0% slower)
keep() 50k overwrites (130k live) 1,416.6 us 1,684.8 us (+18.9%) 1,661.0 us (+17.2%)
keep() 50k remove+insert churn 1,708.5 us 2,491.5 us (+45.8%) 2,469.4 us (+44.5%)
textures_at() 4,096 slots (130k live) 4.28 us 33.00 us (+672%) 33.11 us (+674%)

Concrete Audit Notes (vs main and #3456)

  1. raw_pair_at(..., None, ...) still eagerly allocates the 8 MiB strides buffer: raw_view_at was updated to write stride 0 when buffer.is_none(), but raw_pair_at (descriptor/host.rs:665-666) still calls self.write_stride(index, 4) unconditionally. Verified directly on RTX 5070: calling raw_pair_at(pair, None, 0) on a fresh heap flips strides from false to true (marks=false, made=0 B).
  2. Deferred 3.71 ms materialization under self.made lock: On active view heaps, HostHeap::new (6.82 ms) + first strides()/marks() (3.71 ms) totals 10.53 ms (near parity with main's 11.19 ms), and if the first trigger is a mirrored buffer view, strides_buf() / marks_buf() (upload_buffer + write_bytes over 8/16 MiB WC memory) and made.resize(self.count, 0) execute while holding self.made.lock(). Lazy allocation therefore only saves the 24 MiB + 7.1 MiB on instantiated view heaps that never receive buffer views or view-marking draws.
  3. Locking in keep(): Unlike #3456, #2971 calls crate::host::retire(old) and drops Arc<Shadow> while still holding self.kept.lock(), and performs an extra kept.get(&index) lookup under --features diagnostics. Dropping the lock before retiring/dropping old (as #3456 does) is cleaner and avoids lock-order nesting.

AI-assisted with Gemini 4 Neon.

<!-- greyfinch-sync:Marvisak/VIctory:review:6084527749 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2971#pullrequestreview-6084527749). Originally posted by [Desamodeth](https://github.com/Desamodeth) on 2026-11-27T06:51:12Z. **Review:** COMMENTED --- Independent RTX 5070 + WARP verification, diff audit, and head-to-head Release benchmark against `main` (`63bcca43`) and competing PR #3456 (`28fde825`) — synthetic fixtures only, no game files. ### Test & Lint Verification (`ba430844`) - `cargo clippy --locked -p victory-gpu --lib --tests -- -D warnings` (default and `--features diagnostics`): clean; `cargo xtask policy`: 191 files ok. - **RTX 5070** (Windows 11, Ryzen 7 9800X3D, `--test-threads=1`): `descriptor::` **22/23 passed** (`empty_view_heap_defers_stride_and_mark_tables` passes; only failure is the pre-existing NVIDIA 1M view-heap cap assertion in `dynamic_slots_are_held_until_released`, identical to `main`), `bindless::` **3/3 passed**. - **WARP** (`VICTORY_D3D12_WARP=1`, `--features diagnostics`, `--test-threads=1`): `descriptor::` **23/23 passed**, `bindless::` **3/3 passed**. ### Deterministic Memory & Interleaved Release Timings (RTX 5070 1M-slot heap: `count=934,464`, `dynamic=65,536`, 5 forward+reverse pairs = 10 runs each, median [min..max]) - **Empty heap init:** `0 B` eager for `kept` / `made` / `strides` / `marks` (vs `46.39 MiB` on `main` and `31.13 MiB` on `#3456`). - **Occupancy crossover for `kept` (`HashMap<u32, KeptEntry>`):** Identical to #3456 (`6.25 MiB` at 130k live slots = `-59.0%` vs `main`'s `15.26 MiB`; crosses over at `458,753` slots = `45.9%` occupancy jumping to `25.00 MiB`; reaches `50.00 MiB` at 1M slots and never shrinks after clear). | Workload (1M heap) | `main` (`63bcca43`) | `#2971` (`ba430844`) | `#3456` (`28fde825`) | |---|---:|---:|---:| | `HostHeap::new(false, 1M)` | 11,186.6 us | **6,818.7 us (-39.0%)** | 9,988.9 us (-10.7%) | | First `strides()` + `marks()` | 0.0 us (eager) | **3,710.2 us** `[3,347..4,214]` | 0.0 us (eager) | | `evict()` scan, 1k live (0 hits) | 1,065.5 us | **2.19 us (-99.8%)** | 2.24 us (-99.8%) | | `evict()` scan, 130k live (0 hits) | 1,275.0 us | **576.3 us (-54.8%)** | 584.2 us (-54.2%) | | `evict()` 500 hits, 130k live | 1,448.2 us | **688.5 us (-52.5%)** | 707.1 us (-51.2%) | | `evict()` scan, 500k live (0 hits) | 2,185.6 us | **2,777.4 us (+27.1% slower)** | 2,820.4 us (+29.0% slower) | | `keep()` 50k overwrites (130k live) | 1,416.6 us | **1,684.8 us (+18.9%)** | 1,661.0 us (+17.2%) | | `keep()` 50k remove+insert churn | 1,708.5 us | **2,491.5 us (+45.8%)** | 2,469.4 us (+44.5%) | | `textures_at()` 4,096 slots (130k live) | 4.28 us | **33.00 us (+672%)** | 33.11 us (+674%) | ### Concrete Audit Notes (vs `main` and `#3456`) 1. **`raw_pair_at(..., None, ...)` still eagerly allocates the 8 MiB `strides` buffer:** `raw_view_at` was updated to write stride `0` when `buffer.is_none()`, but `raw_pair_at` (`descriptor/host.rs:665-666`) still calls `self.write_stride(index, 4)` unconditionally. Verified directly on RTX 5070: calling `raw_pair_at(pair, None, 0)` on a fresh heap flips `strides` from `false` to `true` (`marks=false`, `made=0 B`). 2. **Deferred 3.71 ms materialization under `self.made` lock:** On active view heaps, `HostHeap::new` (`6.82 ms`) + first `strides()`/`marks()` (`3.71 ms`) totals `10.53 ms` (near parity with `main`'s `11.19 ms`), and if the first trigger is a mirrored buffer view, `strides_buf()` / `marks_buf()` (`upload_buffer` + `write_bytes` over 8/16 MiB WC memory) and `made.resize(self.count, 0)` execute while holding `self.made.lock()`. Lazy allocation therefore only saves the 24 MiB + 7.1 MiB on instantiated view heaps that never receive buffer views or view-marking draws. 3. **Locking in `keep()`:** Unlike #3456, #2971 calls `crate::host::retire(old)` and drops `Arc<Shadow>` while still holding `self.kept.lock()`, and performs an extra `kept.get(&index)` lookup under `--features diagnostics`. Dropping the lock before retiring/dropping `old` (as #3456 does) is cleaner and avoids lock-order nesting. AI-assisted with Gemini 4 Neon.
0xKaji commented 2026-11-27 11:20:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xKaji on 2026-11-27T11:20:08Z.


Thanks @Desamodeth for the thorough audit and benchmarks! Updated PR #2971 to address both concrete points:

  1. HostHeap::raw_pair_at(..., None, ...) now writes stride 0 instead of 4, avoiding eager 8 MiB strides buffer allocation on null pairs (and updated empty_view_heap_defers_stride_and_mark_tables to cover it).
  2. HostHeap::keep now drops self.kept lock before diagnostics checks, crate::host::retire(old), and dropping the previous entry, and avoids the extra kept.get(&index) lookup.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7216954097 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2971#issuecomment-7216954097). Originally posted by [0xKaji](https://github.com/0xKaji) on 2026-11-27T11:20:08Z. --- Thanks @Desamodeth for the thorough audit and benchmarks! Updated PR #2971 to address both concrete points: 1. `HostHeap::raw_pair_at(..., None, ...)` now writes stride `0` instead of `4`, avoiding eager 8 MiB `strides` buffer allocation on null pairs (and updated `empty_view_heap_defers_stride_and_mark_tables` to cover it). 2. `HostHeap::keep` now drops `self.kept` lock before diagnostics checks, `crate::host::retire(old)`, and dropping the previous entry, and avoids the extra `kept.get(&index)` lookup.
KainanP commented 2026-11-27 13:06:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-27T13:06:23Z.


I ran this through a heap-sync bench in the shape #3425 reports (HostHeap::sync_slots, 18.1 ms/frame for ~384k slots) to check whether the sparse kept map costs anything on the hot path.

Bench: sync_slots_bench on bench/sync-slots (f233390e, on top of f34bcfb8). Each frame, 192 random 64 KiB pages (393,216 slots, the "384k slots" of #3425) of a 2^20-slot placed, write-watched view heap are written. 0, ~9,500 or ~85,000 records among them change, and one sync_heaps runs. Each shape runs without and with 5 title threads writing a view every 20 µs. It checks every changed slot's view address after each sync, and every slot at the end. RTX 4060 Laptop. Base 63bcca4 and the PRs ran interleaved (7 runs for the ~9.5k row, 3 for the others). Ratios are per-run against base. #3265, which doesn't touch the sync, gave ×0.81-1.04 in the same runs, so read anything within ~±15% as noise.

changed records title threads base sync_heaps #2971 ratio title wait/frame, base → #2971
0 0 2.9 ms 3.1 ms ×0.92
0 5 3.6 ms 3.4 ms ×0.92 18 → 17 ms
~9,500 0 12.3 ms 13.3 ms ×1.11
~9,500 5 13.1 ms 13.4 ms ×1.03 64 → 67 ms
~85,000 0 159 ms 164 ms ×1.06
~85,000 5 160 ms 167 ms ×1.12 779 → 716 ms

So it's neutral for speed within noise. If anything, it's slightly slower when many slots are made (a HashMap insert/remove per keep), but the ×1.03-1.12 is inside the run-to-run spread. This is fine for a memory PR, but it isn't a sync speed-up. 0 lost and 0 stale slots in every run, so the dense-lazy made and the None if i < self.count => current bound behaved correctly here. In the same copy bench (copy_simple_bench, same records again), it was also within noise of base (medians 28-44 ms vs 27-43 ms alone).

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7219063312 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2971#issuecomment-7219063312). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-27T13:06:23Z. --- I ran this through a heap-sync bench in the shape #3425 reports (`HostHeap::sync_slots`, 18.1 ms/frame for ~384k slots) to check whether the sparse `kept` map costs anything on the hot path. **Bench:** `sync_slots_bench` on [`bench/sync-slots`](https://github.com/KainanP/VIctory/commits/bench/sync-slots) (`f233390e`, on top of `f34bcfb8`). Each frame, 192 random 64 KiB pages (393,216 slots, the "384k slots" of #3425) of a 2^20-slot placed, write-watched view heap are written. 0, ~9,500 or ~85,000 records among them change, and one `sync_heaps` runs. Each shape runs without and with 5 title threads writing a view every 20 µs. It checks every changed slot's view address after each sync, and every slot at the end. RTX 4060 Laptop. Base `63bcca4` and the PRs ran interleaved (7 runs for the ~9.5k row, 3 for the others). Ratios are per-run against base. #3265, which doesn't touch the sync, gave ×0.81-1.04 in the same runs, so read anything within ~±15% as noise. | changed records | title threads | base `sync_heaps` | #2971 | ratio | title wait/frame, base → #2971 | |---|---|---|---|---|---| | 0 | 0 | 2.9 ms | 3.1 ms | ×0.92 | | | 0 | 5 | 3.6 ms | 3.4 ms | ×0.92 | 18 → 17 ms | | ~9,500 | 0 | 12.3 ms | 13.3 ms | ×1.11 | | | ~9,500 | 5 | 13.1 ms | 13.4 ms | ×1.03 | 64 → 67 ms | | ~85,000 | 0 | 159 ms | 164 ms | ×1.06 | | | ~85,000 | 5 | 160 ms | 167 ms | ×1.12 | 779 → 716 ms | So it's neutral for speed within noise. If anything, it's slightly slower when many slots are made (a `HashMap` insert/remove per `keep`), but the ×1.03-1.12 is inside the run-to-run spread. This is fine for a memory PR, but it isn't a sync speed-up. 0 lost and 0 stale slots in every run, so the dense-lazy `made` and the `None if i < self.count => current` bound behaved correctly here. In the same copy bench (`copy_simple_bench`, same records again), it was also within noise of base (medians 28-44 ms vs 27-43 ms alone). _AI use: Claude Code (Claude Opus 5.5)._
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2971:upstream-pr/2971'
git switch 'upstream-pr/2971'

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 'upstream-pr/2971'
git switch 'upstream-pr/2971'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2971'
git switch 'upstream-pr/2971'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2971'
git switch 'main'
git merge --squash 'upstream-pr/2971'
git switch 'main'
git merge --ff-only 'upstream-pr/2971'
git switch 'main'
git merge 'upstream-pr/2971'
git push origin 'main'
Sign in to join this conversation.
No reviewers
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
Marvisak/VIctory!2969
No description provided.