GPU/Placement: defer free() reap, on-demand place() reap, and O(1) heap metadata #2955

Open
github-bot wants to merge 1 commit from github-bot/gh-2955 into main AGit
Owner

@⁠RVZO6 on GitHub · 2026-11-26 01:30 UTC · original
RVZO6:rvzo/placement-fast → main · +236 −31 · 1 files · 1 commits · open

Summary

Eliminates redundant heap reaping and O(N) free-list scans in crates/victory-gpu/src/placement.rs:

  • Deferred free() reap: free() releases the placed resource and marks the owning heap dirty instead of immediately walking all heaps on every free.
  • On-demand place() reap: place() reaps pending frees only when needed to satisfy a new placement request (explicitly documented in the module doc comment as a deferred-reap lifecycle).
  • O(1) heap metadata: tracks largest free block / free-bytes metadata per heap so place() skips heaps that cannot satisfy an allocation without linearly scanning their free lists.

Verification

  • Verified green on Windows MSVC + WARP SM 6.6 CI (run 45768895488): cargo clippy --workspace --all-targets --locked -- -D warnings, --all-features, xtask policy, and full workspace tests (victory-gpu: 233 passed, 0 failed, including deferred_free_and_on_demand_reap_reuse_without_extra_heaps and free_list_metadata_stays_exact_across_fragmentation_and_coalescing).
  • Not run: the title; any hardware GPU.

AI-assisted: T3 Code (Antigravity, gemini-4-neon).

**@⁠RVZO6** on GitHub · 2026-11-26 01:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2955) `RVZO6:rvzo/placement-fast` → `main` · +236 −31 · 1 files · 1 commits · open ### Summary Eliminates redundant heap reaping and O(N) free-list scans in `crates/victory-gpu/src/placement.rs`: - **Deferred `free()` reap**: `free()` releases the placed resource and marks the owning heap dirty instead of immediately walking all heaps on every free. - **On-demand `place()` reap**: `place()` reaps pending frees only when needed to satisfy a new placement request (explicitly documented in the module doc comment as a deferred-reap lifecycle). - **O(1) heap metadata**: tracks largest free block / free-bytes metadata per heap so `place()` skips heaps that cannot satisfy an allocation without linearly scanning their free lists. ### Verification - Verified green on Windows MSVC + WARP SM 6.6 CI ([run 45768895488](https://github.com/RVZO6/VIctory/actions/runs/45768895488)): `cargo clippy --workspace --all-targets --locked -- -D warnings`, `--all-features`, `xtask policy`, and full workspace tests (`victory-gpu`: 233 passed, 0 failed, including `deferred_free_and_on_demand_reap_reuse_without_extra_heaps` and `free_list_metadata_stays_exact_across_fragmentation_and_coalescing`). - **Not run:** the title; any hardware GPU. AI-assisted: T3 Code (Antigravity, gemini-4-neon).
Eliminate O(P^2) COM refcount reaping, O(H*F) free-list scans, and
duplicate GetResourceAllocationInfo queries in crates/victory-gpu/src/placement.rs:
- Defer reap() in free() (O(1) push with doubling high-water backoff past
  1024 pending entries; frame passes already reap via free_bytes()/stats()).
- Check existing heaps in place()/allocate() before calling reap(), avoiding
  repeated COM AddRef/Release scans over in-flight textures when room exists.
- Index heaps in BTreeMap<u64, Heap> (preserving first-fit creation order
  with O(log H) lookup on reap/unplace) and track per-heap free_bytes and
  max_free in FreeList for O(1) skip of full/fragmented heaps, O(1) empty
  checks, and O(H) free_bytes()/stats().
- Cache GetResourceAllocationInfo from fits() in a 1-entry thread-local
  keyed by explicit D3D12_RESOURCE_DESC fields + device pointer and consume
  it in the immediately following place() call.

Measured (--release bench_placement_freelist_skip_and_sum, median of 3 runs,
20k alloc + free_bytes sums across 16 fragmented heaps):
- 314.520 ms -> 1.447 ms (217x, -99.54%)

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:18:32 +00:00
github-bot changed title from GPU/Placement: defer free() reap, on-demand place() reap, O(1) heap metadata, and TLS fits->place alloc-info cache to GPU/Placement: defer free() reap, on-demand place() reap, and O(1) heap metadata 2026-11-26 07:27:32 +00:00
github-bot force-pushed github-bot/gh-2955 from aee97ff82b to f9d79afee8 2026-11-26 07:27:33 +00:00 Compare
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 05:43 UTC · original · edited 2026-11-26 07:19 UTC

Automated triage for the maintainers.

Needs work. Thanks for f9d79af. The thread_local! cache and the ignored benchmark are gone, and the module docs now say when deferred ranges and empty heaps are given back. The FreeList totals still look exact to me, and allocate reaps before it makes a new heap.

The main point is still open: nothing shows that place, free or reap cost measurable time in a real frame. The PR now adds a REAP_THRESHOLD/next_reap_at backoff and changes when memory is returned, without any measurement. A profile or frame-report line from a title run showing time spent in placement would make the case. Without one, this is extra mechanism for no shown gain.

Smaller points:

  • The description says free() "marks the owning heap dirty", but no such flag exists.
  • FreeList::take recomputes max_free by scanning all ranges whenever the largest range is used, so "O(1) heap metadata" overstates it.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/2955#issuecomment-7183741414) · edited 2026-11-26 07:19 UTC <!-- victory-triage v1 head=f9d79afee8f64551df25d9787c3303c118f550cf verdict=needs-work at=2026-11-26T07:19:06Z --> Automated triage for the maintainers. **Needs work.** Thanks for f9d79af. The `thread_local!` cache and the ignored benchmark are gone, and the module docs now say when deferred ranges and empty heaps are given back. The `FreeList` totals still look exact to me, and `allocate` reaps before it makes a new heap. The main point is still open: nothing shows that `place`, `free` or `reap` cost measurable time in a real frame. The PR now adds a `REAP_THRESHOLD`/`next_reap_at` backoff and changes when memory is returned, without any measurement. A profile or frame-report line from a title run showing time spent in placement would make the case. Without one, this is extra mechanism for no shown gain. Smaller points: - The description says `free()` "marks the owning heap dirty", but no such flag exists. - `FreeList::take` recomputes `max_free` by scanning all ranges whenever the largest range is used, so "O(1) heap metadata" overstates it. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠RVZO6 on GitHub · 2026-11-26 06:56 UTC · original

Addressed triage feedback in f9d79af:

  • Removed the thread_local! DescKey/LAST_ALLOC_INFO cache and restored plain GetResourceAllocationInfo calls in fits() and place().
  • Removed the #[ignore] bench_placement_freelist_skip_and_sum microbenchmark from unit tests.
  • Documented the deferred-reap lifecycle explicitly in the module docs and updated the PR title/description to match.
  • Verified green on Windows MSVC + WARP SM 6.6 CI (run 45768895488): 233 passed, 0 failed in victory-gpu, both clippy profiles, and xtask policy. Not run: the title; any hardware GPU.
**@⁠RVZO6** on GitHub · 2026-11-26 06:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2955#issuecomment-7184936849) Addressed triage feedback in `f9d79af`: - Removed the `thread_local!` `DescKey`/`LAST_ALLOC_INFO` cache and restored plain `GetResourceAllocationInfo` calls in `fits()` and `place()`. - Removed the `#[ignore]` `bench_placement_freelist_skip_and_sum` microbenchmark from unit tests. - Documented the deferred-reap lifecycle explicitly in the module docs and updated the PR title/description to match. - Verified green on Windows MSVC + WARP SM 6.6 CI ([run 45768895488](https://github.com/RVZO6/VIctory/actions/runs/45768895488)): 233 passed, 0 failed in `victory-gpu`, both clippy profiles, and `xtask policy`. **Not run:** the title; any hardware GPU.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2955/head:github-bot/gh-2955'
git switch 'github-bot/gh-2955'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2955'
git switch 'github-bot/gh-2955'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2955'
git switch 'github-bot/gh-2955'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2955'
git switch 'main'
git merge --squash 'github-bot/gh-2955'
git switch 'main'
git merge --ff-only 'github-bot/gh-2955'
git switch 'main'
git merge 'github-bot/gh-2955'
git push origin 'main'
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/Marvisak--VIctory!2955
No description provided.