Release idle snapshots and optimize CPU write-range bookkeeping #357
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/readmet3xt-lab--foxhound!357
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-357"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@zzzz-26 on GitHub · 2026-12-01 17:55 UTC · original
zzzz-26:optimize-memory-bookkeeping-20261201-095455→main· +483 −53 · 6 files · 72 commits · closed without mergingSummary
Recreates PR #108, which was accidentally closed, using the changes from commit 5a261b5 on a clean branch.
This PR addresses two independent inefficiencies in the GPU shadow memory subsystem:
These changes improve algorithmic scaling and allocation lifetime management without intentionally changing rendering functionality.
Implementation
Write-range coverage
The previous implementation repeatedly subtracted existing write declarations from a vector of uncovered intervals.
Each subtraction could allocate another temporary vector and traverse previously generated fragments.
With heavily fragmented declarations, this could approach quadratic time complexity.
The updated implementation maintains exact write declarations in sorted order and calculates uncovered portions through a linear interval traversal.
This reduces repeated traversal and temporary allocations while preserving the original coverage semantics.
Duplicate write declarations
Repeated GPU write declarations previously required linear searches.
The updated implementation uses binary search over sorted declarations, reducing duplicate lookup from linear to logarithmic complexity.
Unique insertion remains linear because subsequent vector entries may need to be shifted. The mixed declaration benchmark accounts for this insertion cost.
Write-range retirement
Completed write declarations are retired through a merge-based traversal instead of repeated membership checks.
Both relay and non-relay completion paths benefit, with particularly significant improvements in the non-relay path.
Exact declaration identities, overlapping declarations, submission flight counts and resource lifetime semantics are preserved.
Snapshot memory management
Idle snapshot expiration can be disabled using:
VICTORY_IDLE_TRIM=0No intentional changes are made to rendering resolution, shaders, upscaling, frame generation or launcher functionality.
CPU performance benchmarks
Original measurements recorded on November 30, 2026.
Test environment
7281175Results
All execution times are in microseconds per benchmark operation.
At 1024 ranges, the fragmented coverage benchmark eliminates approximately 99.65% of its original execution time.
The mixed declaration benchmark decreases from approximately 24.46 ms to 0.367 ms, including sorted-vector insertion costs.
These results demonstrate improved algorithmic scaling rather than merely faster execution at a fixed input size.
Benchmark methodology
The standalone benchmark compares the new production helpers against reproductions of the previous algorithms within the same executable.
Both implementations are warmed before measurement.
Measurement order alternates across 11 samples of 20 operations, with published results representing medians across three independent process runs.
Coverage workloads deliberately contain fragmented, disjoint declarations to stress the previous algorithm.
Mixed workloads include permuted insertions and repeated declarations, accounting for sorted-vector insertion costs.
Both retirement implementations receive equivalent cloned inputs.
The previous relay implementation already used binary search, while the non-relay implementation performed linear membership checks.
Correctness assertions execute before measurement.
Algorithmic improvements
Retirement complexities assume sorted completion ranges. Additional sorting is necessary when that invariant is absent.
Expected gameplay impact
Potential benefits include:
These benchmarks measure isolated CPU bookkeeping operations, not complete game frames.
Actual FPS improvements depend on real declaration distributions, submission frequency, CPU/GPU overlap and whether the affected operations occur on the frame's critical path.
Idle snapshot eviction may introduce reallocation costs when previously released buffers are needed again.
No measured gameplay FPS improvement or RAM reduction is claimed.
Validation
The original implementation passed:
Reproduction commands:
Follow-up optimization opportunities
Additional static source analysis identified the following independent optimization candidates.
These are not implemented or benchmarked by this PR.
Confidence refers to the source-code finding rather than a guaranteed gameplay performance improvement.
1. Ordered stale-page detection
shadow.rs::stale_pages_in()performs a binary search into sorted write-watch results for each previously copied page.An ordered traversal could replace O(P log W) searching with approximately O(P + W) work over the relevant ranges.
Shadow::stale_under_writes()also constructs a vector solely to determine whether any stale pages exist. An allocation-free early-exit iterator could eliminate this unnecessary work.Never-copied pages and existing generation semantics must remain correctly handled.
2. Reuse sorted pending declarations
This PR introduces a sorted-declaration invariant.
Other paths, including
Shadow::update(), still collect and sort overlapping ranges independently.These paths could reuse the new range helpers and eliminate redundant sorting after verifying all mutation invariants.
Exact declaration identities must remain independent for retirement and flight accounting.
A separately maintained coalesced coverage representation could further accelerate repeated overlap queries.
3. Linear sent-range merging
SentRuns::note_joined()concatenates already sorted interval sequences and sorts the resulting vector.A two-way interval merge could eliminate intermediate allocations and redundant sorting.
The practical benefit should be measured against Rust's existing adaptive sorting implementation.
4. GPU-address VRAM accounting
shadow.rs::by_address()increments its allocation allowance before confirming whether the requested allocation fits or whether GPU allocation succeeds.Failed reservations are not rolled back, and destruction does not return the corresponding allowance.
If this counter represents live allocations, inaccurate accounting can force otherwise eligible resources into system memory unnecessarily.
On discrete GPUs, this can introduce additional PCIe memory traffic and higher GPU memory access latency.
A lifetime-aware atomic reservation guard should be investigated, with budget release tied to actual resource retirement.
5. Failed arena allocation cleanup
Memory::another()and related initialization paths reserve raw virtual memory before subsequent fallible resource creation operations.Failed initialization can leave those allocations committed.
An RAII allocation owner could ensure cleanup on every failure path.
This is principally a memory-exhaustion and stability fix.
6. Exact-view cache retention
The exact-view recycling pool has a byte limit, while live cached views are primarily pruned according to lookup activity and entry count.
Periodic byte-aware eviction could release idle live-map entries even when new cache misses stop occurring.
Existing GPU quarantine, ownership checks and fence requirements must be preserved.
Pressure-driven eviction should reduce total retained memory rather than simply transferring allocations into another cache.
7. Pressure-aware buffer preallocation
The speculative allocation worker creates thousands of small D3D12 buffers to reduce resource creation stalls.
However, CPU-side preallocation does not fully account for system memory pressure.
Pressure-aware targets, bounded allocation-failure backoff and reclamation of unused preallocated resources could reduce memory pressure without eliminating preallocation's streaming benefits.
Hysteresis should prevent repeated trimming and refilling.
8. Redundant address-memory refresh scheduling
memory.rs::Memory::bring_up()refreshes every known address-backed shadow for qualifying command lists.Although deferred refresh requests are deduplicated, traversal, locking and hash lookups still occur.
A bulk scheduling interface could reduce lock acquisitions without changing synchronization behavior.
Dirty-generation tracking could provide further improvements, but must preserve initialization across independently recorded and submitted command lists.
9. Redundant snapshot copying
Historical profiling comments in the source describe approximately 1050 MB of copying per frame, consuming 72-86 ms, despite approximately 100 MB of changed data.
These are historical observations, not measurements of this PR.
Reliable GPU write tracking could potentially eliminate substantial unnecessary copying.
The existing experimental kept-snapshot mode should not be enabled globally without resolving its known coherence risks.
Selective shader write instrumentation or conservative dirty-region tracking may provide a path toward reducing snapshot traffic while retaining the existing implementation as a correctness fallback.
10. Sparse CPU snapshots
Snapshots currently allocate capacity for the entire shadow even when declared writes cover only a small portion.
Demand-committed virtual memory could preserve stable snapshot addresses while reducing committed capacity.
Deferred raw pointers, initialization state, worker-thread access and copy-back lifetimes must remain valid.
Reserved virtual address space, committed memory and resident working-set memory should be measured separately.
11. Arena reclamation
GPU-address arenas and upload arenas retain historical allocation peaks.
Per-arena occupancy tracking, allocation consolidation, fence-safe reclamation and descriptor lifetime management could substantially reduce retained memory.
Persistent GPU-generated data must not be discarded merely because CPU-side ownership appears inactive.
12. Resource suballocation and staging duplication
Numerous individually committed D3D12 resources may incur allocation overhead, alignment padding and driver metadata costs.
Shared-heap suballocation could reduce these costs where resource states and synchronization requirements permit.
The address-memory subsystem also retains multiple representations of memory. Eliminating unnecessary staging copies or permanently resident allocations could provide further memory reductions.
These are architectural changes requiring independent correctness and performance validation.
Recommended follow-up validation
Future optimization work should measure:
Prioritize measured critical-path savings over isolated microbenchmark speedups.
References
The standalone benchmark source is retained for reproducibility.
Raw benchmark CSV files and separate benchmark documentation are intentionally excluded from the replacement commit.
AI disclosure
Claude Opus 5.5 assisted with codebase analysis, identification of algorithmic and memory-management inefficiencies, development of optimization strategies and preparation of this pull request.
AI-assisted findings and changes remain subject to independent review, compilation, regression testing and gameplay validation.
Replacement branch validation
The replacement branch has not yet been independently compiled or benchmarked. The reported results are from the original implementation.
@Aniseto on GitHub · 2026-12-01 18:10 UTC · original
Ran the three named
victory-gputest groups ata49e5a28on an NVIDIA Blackwell desktop part with 16 GB of VRAM.Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, debug build, detached worktree at the exact PR head, own
CARGO_TARGET_DIR, no local patches.All three groups pass here, matching the description's four write-range, five idle-pool and nine relay tests. These are synthetic tests; no title was run, so the CPU-overhead and snapshot-retention effects were not measured on a real workload.
Not tested: the full workspace suite, a retail title, CPU-time A/B for write-range tracking or snapshot release, Wine, AMD adapters, release profile, game data.
AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Pull request closed