GPU: bound shadow buffer lookup by maximum registered size instead of 64 entries #2094

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/2096 into main
fuzeofficlal commented 2026-11-25 04:49:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T04:49:28Z.


Refs #906.

Summary

  • Replace the fixed .take(64) cap in shadow::find (crates/victory-gpu/src/shadow.rs) with a reverse scan bounded by the maximum buffer size currently registered in BUFFERS (lowest = end.saturating_sub(max_size), returning None immediately when lowest > address).
  • Track max_size on Buffers::insert and recompute it on Buffers::remove when the previous maximum-size entry is unregistered, so misses reaching loose() stop at the live maximum buffer bound while lookups still reach a covering outer buffer past more than 64 smaller inner buffers.

Verification

  • shadow::tests::find_reaches_covering_buffer_past_many_inner_buffers
  • shadow::tests::find_stops_at_max_size_bound_and_tightens_on_unregister
  • cargo clippy -p victory-gpu --tests --locked -- -D warnings and cargo xtask policy: passed.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5485373615 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2096). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T04:49:28Z. --- Refs #906. ### Summary - Replace the fixed `.take(64)` cap in `shadow::find` (`crates/victory-gpu/src/shadow.rs`) with a reverse scan bounded by the maximum buffer size currently registered in `BUFFERS` (`lowest = end.saturating_sub(max_size)`, returning `None` immediately when `lowest > address`). - Track `max_size` on `Buffers::insert` and recompute it on `Buffers::remove` when the previous maximum-size entry is unregistered, so misses reaching `loose()` stop at the live maximum buffer bound while lookups still reach a covering outer buffer past more than 64 smaller inner buffers. ### Verification - `shadow::tests::find_reaches_covering_buffer_past_many_inner_buffers` - `shadow::tests::find_stops_at_max_size_bound_and_tightens_on_unregister` - `cargo clippy -p victory-gpu --tests --locked -- -D warnings` and `cargo xtask policy`: passed.
DenRakEiw commented 2026-11-25 04:56:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T04:56:57Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib shadow:: — 6 passed, 0 failed (including overflowing_ranges_are_rejected_without_panic and find_scans_past_sixty_four_siblings_and_picks_tightest_equal_start)
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean overflow guards on shadow range arithmetic and complete sibling scan in find(). Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6052066805 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2096#pullrequestreview-6052066805). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T04:56:57Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib shadow::` — 6 passed, 0 failed (including `overflowing_ranges_are_rejected_without_panic` and `find_scans_past_sixty_four_siblings_and_picks_tightest_equal_start`) - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean overflow guards on shadow range arithmetic and complete sibling scan in `find()`. Looks good. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 05:02:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T05:02:21Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Shadow range arithmetic overflow-guarded + scan — memory-safety hardening on the shadow-memory path.

<!-- greyfinch-sync:Marvisak/VIctory:review:6052105132 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2096#pullrequestreview-6052105132). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T05:02:21Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Shadow range arithmetic overflow-guarded + scan — memory-safety hardening on the shadow-memory path.
upstream-sync changed title from [PR #2096] GPU: guard shadow range arithmetic against overflow and scan all buffers in find() to [PR #2096] GPU: bound shadow buffer lookup by maximum registered size instead of 64 entries 2026-11-25 11:03:59 +00:00
Marvisak commented 2026-11-25 11:05:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T10:36:25Z.


Automated triage for the maintainers.

Merge candidate. shadow::find now scans backwards only from end - max_size (find_buffer), where Buffers tracks the largest registered length and recomputes it when the largest entry is removed or replaced; a buffer that covers [address, end) must start at or after that bound, so lookups still reach an outer buffer past many smaller ones while misses reaching loose() stop early. The overflow guards and the equal-start tie-breaker are gone. #402 overlaps but currently has merge conflicts; this one merges cleanly. CI passes.

On your reply: confirmed in 2f43424, this is what was asked. A minor follow-up, not a blocker: Buffers::remove rescans the whole map each time an entry of the maximum size goes, which is O(n) per release if many buffers share that size; a size-count map would make it O(log n).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7159924855 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2096#issuecomment-7159924855). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T10:36:25Z. --- <!-- victory-triage v1 head=2f434243f82c511c9169b8e5b64363fc3ac0caa9 verdict=merge-candidate at=2026-11-25T11:23:40Z --> Automated triage for the maintainers. **Merge candidate.** `shadow::find` now scans backwards only from `end - max_size` (`find_buffer`), where `Buffers` tracks the largest registered length and recomputes it when the largest entry is removed or replaced; a buffer that covers `[address, end)` must start at or after that bound, so lookups still reach an outer buffer past many smaller ones while misses reaching `loose()` stop early. The overflow guards and the equal-start tie-breaker are gone. #402 overlaps but currently has merge conflicts; this one merges cleanly. CI passes. On your reply: confirmed in `2f43424`, this is what was asked. A minor follow-up, not a blocker: `Buffers::remove` rescans the whole map each time an entry of the maximum size goes, which is O(n) per release if many buffers share that size; a size-count map would make it O(log n). --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-25 11:05:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T10:51:58Z.


Updated in 2f434243 per triage feedback:

  • Bounded find_buffer by the maximum currently registered buffer size (lowest = end.saturating_sub(max_size) over (lowest, 0)..=(address, usize::MAX)), tightening max_size on unregister when the largest buffer is removed so misses stop early instead of walking the map.
  • Dropped all u64::MAX overflow/saturating guards and the equal-start tie-breaker.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7160276566 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2096#issuecomment-7160276566). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T10:51:58Z. --- Updated in `2f434243` per triage feedback: - Bounded `find_buffer` by the maximum currently registered buffer size (`lowest = end.saturating_sub(max_size)` over `(lowest, 0)..=(address, usize::MAX)`), tightening `max_size` on `unregister` when the largest buffer is removed so misses stop early instead of walking the map. - Dropped all `u64::MAX` overflow/saturating guards and the equal-start tie-breaker.
Desamodeth commented 2026-11-26 21:10:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Desamodeth on 2026-11-26T21:10:37Z.

Code review location: crates/victory-gpu/src/shadow.rs; line 831

@@ -783,10 +783,57 @@ struct Entry {
     shadow: Option<Arc<Shadow>>,
 }
 
+struct Buffers {
+    map: BTreeMap<(u64, usize), Entry>,
+    /// Maximum registered buffer size in `map`, bounding backward scans on misses.
+    max_size: u64,
+}
+
+impl Buffers {
+    const fn new() -> Self {
+        Self {
+            map: BTreeMap::new(),
+            max_size: 0,
+        }
+    }
+
+    fn insert(&mut self, resource: usize, start: u64, len: u64) {
+        if let Some(prev) = self.map.insert(
+            (start, resource),
+            Entry {
+                end: start + len,
+                shadow: None,
+            },
+        ) && prev.end - start == self.max_size
+            && len < self.max_size
+        {
+            self.recompute_max_size();
+        }
+        self.max_size = self.max_size.max(len);
+    }
+
+    fn remove(&mut self, resource: usize, start: u64) -> Option<Entry> {
+        let removed = self.map.remove(&(start, resource))?;
+        if removed.end - start == self.max_size {
+            self.recompute_max_size();
+        }
+        Some(removed)
+    }
+
+    fn recompute_max_size(&mut self) {
+        self.max_size = self
+            .map
+            .iter()
+            .map(|(&(start, _), e)| e.end - start)
+            .max()
+            .unwrap_or(0);
+    }
+}

Keep the bound exact on replacement and removal. This is the size-count variant measured above.

struct Buffers {
    map: BTreeMap<(u64, usize), Entry>,
    /// Number of live registrations of each buffer length.
    size_counts: BTreeMap<u64, usize>,
    /// Cached so range lookups do not need to visit the size index.
    max_size: u64,
}

impl Buffers {
    const fn new() -> Self {
        Self {
            map: BTreeMap::new(),
            size_counts: BTreeMap::new(),
            max_size: 0,
        }
    }

    fn insert(&mut self, resource: usize, start: u64, len: u64) {
        if let Some(prev) = self.map.insert(
            (start, resource),
            Entry {
                end: start + len,
                shadow: None,
            },
        ) {
            let previous_len = prev.end - start;
            if previous_len == len {
                return;
            }
            self.forget_size(previous_len);
        }
        *self.size_counts.entry(len).or_default() += 1;
        self.max_size = self.max_size.max(len);
    }

    fn remove(&mut self, resource: usize, start: u64) -> Option<Entry> {
        let removed = self.map.remove(&(start, resource))?;
        self.forget_size(removed.end - start);
        Some(removed)
    }

    fn forget_size(&mut self, len: u64) {
        let count = self.size_counts.get_mut(&len).expect("registered buffer length");
        *count -= 1;
        if *count == 0 {
            self.size_counts.remove(&len);
            if len == self.max_size {
                self.max_size = self.size_counts.last_key_value().map_or(0, |(&size, _)| size);
            }
        }
    }
}
<!-- greyfinch-sync:Marvisak/VIctory:review-comment:4713391674 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2096#discussion_r4713391674). Originally posted by [Desamodeth](https://github.com/Desamodeth) on 2026-11-26T21:10:37Z. **Code review location:** `crates/victory-gpu/src/shadow.rs`; line 831 ~~~~diff @@ -783,10 +783,57 @@ struct Entry { shadow: Option<Arc<Shadow>>, } +struct Buffers { + map: BTreeMap<(u64, usize), Entry>, + /// Maximum registered buffer size in `map`, bounding backward scans on misses. + max_size: u64, +} + +impl Buffers { + const fn new() -> Self { + Self { + map: BTreeMap::new(), + max_size: 0, + } + } + + fn insert(&mut self, resource: usize, start: u64, len: u64) { + if let Some(prev) = self.map.insert( + (start, resource), + Entry { + end: start + len, + shadow: None, + }, + ) && prev.end - start == self.max_size + && len < self.max_size + { + self.recompute_max_size(); + } + self.max_size = self.max_size.max(len); + } + + fn remove(&mut self, resource: usize, start: u64) -> Option<Entry> { + let removed = self.map.remove(&(start, resource))?; + if removed.end - start == self.max_size { + self.recompute_max_size(); + } + Some(removed) + } + + fn recompute_max_size(&mut self) { + self.max_size = self + .map + .iter() + .map(|(&(start, _), e)| e.end - start) + .max() + .unwrap_or(0); + } +} ~~~~ --- Keep the bound exact on replacement and removal. This is the size-count variant measured above. ```suggestion struct Buffers { map: BTreeMap<(u64, usize), Entry>, /// Number of live registrations of each buffer length. size_counts: BTreeMap<u64, usize>, /// Cached so range lookups do not need to visit the size index. max_size: u64, } impl Buffers { const fn new() -> Self { Self { map: BTreeMap::new(), size_counts: BTreeMap::new(), max_size: 0, } } fn insert(&mut self, resource: usize, start: u64, len: u64) { if let Some(prev) = self.map.insert( (start, resource), Entry { end: start + len, shadow: None, }, ) { let previous_len = prev.end - start; if previous_len == len { return; } self.forget_size(previous_len); } *self.size_counts.entry(len).or_default() += 1; self.max_size = self.max_size.max(len); } fn remove(&mut self, resource: usize, start: u64) -> Option<Entry> { let removed = self.map.remove(&(start, resource))?; self.forget_size(removed.end - start); Some(removed) } fn forget_size(&mut self, len: u64) { let count = self.size_counts.get_mut(&len).expect("registered buffer length"); *count -= 1; if *count == 0 { self.size_counts.remove(&len); if len == self.max_size { self.max_size = self.size_counts.last_key_value().map_or(0, |(&size, _)| size); } } } } ```
Desamodeth commented 2026-11-26 21:10:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Desamodeth on 2026-11-26T21:10:37Z.

Review: COMMENTED


The full rescan mentioned in triage is visible in both removal and in-place replacement on 2f434243. With 4,096 equal 4 KiB buffers, removing them one by one visits 8,386,560 remaining entries under the registry mutex. Shrinking all 4,096 at the same keys visits 16,777,216 entries.

CPU time per batch of 4,096 mutations, across two opposite-order runs:

Workload main 63bcca43 This PR Suggested size counts
Remove equal 4 KiB registrations 0.13–0.15 ms 6.48–6.64 ms 0.13–0.15 ms
Replace each 4 KiB registration with 2 KiB 0.09–0.10 ms 13.01–13.21 ms 0.105–0.106 ms
Remove 4,096 distinct sizes, largest first 0.14–0.15 ms 6.49–6.53 ms 0.40–0.42 ms

The suggestion keeps the PR's exact lookup bound and stores one count per distinct length. The extra live heap requested by the index was 192 B for one length, 2,016 B for 64 lengths and 139,968 B for 4,096 lengths. Registering the all-distinct batch also took 0.34–0.36 ms vs 0.16–0.21 ms here. I tested a single counter for ties too. It fixed the equal-size case, but largest-first removal still took 9.27–9.30 ms.

Isolated Windows x64 registry benchmark, Ryzen 7 9800X3D, rustc 1.98.1 release, production mutex and map operations. Each sample started empty, registered disjoint buffers and performed one hit per buffer before timing mutations. Eleven timed samples per case in each run. Separate allocation-counting binary. Checked exact maxima after 6,000 mixed mutations and 18,000 lookups against an exhaustive reference, including shared start addresses and replacements. The covering buffer beyond 64 siblings is still found. The suggestion applies to this head and to this PR applied over current main. Full crate, D3D12 and in-game frequency were outside this CPU measurement. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:review:6080510542 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2096#pullrequestreview-6080510542). Originally posted by [Desamodeth](https://github.com/Desamodeth) on 2026-11-26T21:10:37Z. **Review:** COMMENTED --- The full rescan mentioned in triage is visible in both removal and in-place replacement on `2f434243`. With 4,096 equal 4 KiB buffers, removing them one by one visits 8,386,560 remaining entries under the registry mutex. Shrinking all 4,096 at the same keys visits 16,777,216 entries. CPU time per batch of 4,096 mutations, across two opposite-order runs: | Workload | main `63bcca43` | This PR | Suggested size counts | | --- | ---: | ---: | ---: | | Remove equal 4 KiB registrations | 0.13–0.15 ms | 6.48–6.64 ms | 0.13–0.15 ms | | Replace each 4 KiB registration with 2 KiB | 0.09–0.10 ms | 13.01–13.21 ms | 0.105–0.106 ms | | Remove 4,096 distinct sizes, largest first | 0.14–0.15 ms | 6.49–6.53 ms | 0.40–0.42 ms | The suggestion keeps the PR's exact lookup bound and stores one count per distinct length. The extra live heap requested by the index was 192 B for one length, 2,016 B for 64 lengths and 139,968 B for 4,096 lengths. Registering the all-distinct batch also took 0.34–0.36 ms vs 0.16–0.21 ms here. I tested a single counter for ties too. It fixed the equal-size case, but largest-first removal still took 9.27–9.30 ms. Isolated Windows x64 registry benchmark, Ryzen 7 9800X3D, rustc 1.98.1 release, production mutex and map operations. Each sample started empty, registered disjoint buffers and performed one hit per buffer before timing mutations. Eleven timed samples per case in each run. Separate allocation-counting binary. Checked exact maxima after 6,000 mixed mutations and 18,000 lookups against an exhaustive reference, including shared start addresses and replacements. The covering buffer beyond 64 siblings is still found. The suggestion applies to this head and to this PR applied over current main. Full crate, D3D12 and in-game frequency were outside this CPU measurement. AI-assisted with Codex.
fuzeofficlal commented 2026-11-26 21:34:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T21:34:23Z.


@Desamodeth Thanks for benchmarking those equal-size and descending-removal workloads — the 16x–125x slowdown under the BUFFERS mutex was a great catch!

I rebased onto current main (63bcca43) and updated Buffers in 91104672 to track live registration counts per buffer size in sizes: BTreeMap<u64, usize>, with max_size(&self) -> u64 reading self.sizes.keys().next_back().copied().unwrap_or(0). Inserts, in-place replacements (equal/grow/shrink), and removals are now O(log n) without any full-map rescan while preserving the exact lookup bound.

Added shadow::tests::max_size_tracks_equal_sizes_replacements_and_descending_removals covering equal-size ties, in-place replacements, descending removals, and empty reset; verified all 13 shadow:: tests on both NVIDIA GeForce RTX 5090 and WARP under VICTORY_D3D12_DEBUG=1, plus clippy (default and --all-features) and xtask policy.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203854849 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2096#issuecomment-7203854849). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T21:34:23Z. --- @Desamodeth Thanks for benchmarking those equal-size and descending-removal workloads — the 16x–125x slowdown under the `BUFFERS` mutex was a great catch! I rebased onto current `main` (`63bcca43`) and updated `Buffers` in `91104672` to track live registration counts per buffer size in `sizes: BTreeMap<u64, usize>`, with `max_size(&self) -> u64` reading `self.sizes.keys().next_back().copied().unwrap_or(0)`. Inserts, in-place replacements (equal/grow/shrink), and removals are now O(log n) without any full-map rescan while preserving the exact lookup bound. Added `shadow::tests::max_size_tracks_equal_sizes_replacements_and_descending_removals` covering equal-size ties, in-place replacements, descending removals, and empty reset; verified all 13 `shadow::` tests on both NVIDIA GeForce RTX 5090 and WARP under `VICTORY_D3D12_DEBUG=1`, plus `clippy` (default and `--all-features`) and `xtask policy`.
Desamodeth commented 2026-11-26 21:48:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Desamodeth on 2026-11-26T21:48:53Z.

Code review location: crates/victory-gpu/src/shadow.rs; line 831

@@ -783,10 +783,57 @@ struct Entry {
     shadow: Option<Arc<Shadow>>,
 }
 
+struct Buffers {
+    map: BTreeMap<(u64, usize), Entry>,
+    /// Maximum registered buffer size in `map`, bounding backward scans on misses.
+    max_size: u64,
+}
+
+impl Buffers {
+    const fn new() -> Self {
+        Self {
+            map: BTreeMap::new(),
+            max_size: 0,
+        }
+    }
+
+    fn insert(&mut self, resource: usize, start: u64, len: u64) {
+        if let Some(prev) = self.map.insert(
+            (start, resource),
+            Entry {
+                end: start + len,
+                shadow: None,
+            },
+        ) && prev.end - start == self.max_size
+            && len < self.max_size
+        {
+            self.recompute_max_size();
+        }
+        self.max_size = self.max_size.max(len);
+    }
+
+    fn remove(&mut self, resource: usize, start: u64) -> Option<Entry> {
+        let removed = self.map.remove(&(start, resource))?;
+        if removed.end - start == self.max_size {
+            self.recompute_max_size();
+        }
+        Some(removed)
+    }
+
+    fn recompute_max_size(&mut self) {
+        self.max_size = self
+            .map
+            .iter()
+            .map(|(&(start, _), e)| e.end - start)
+            .max()
+            .unwrap_or(0);
+    }
+}

Verified the fix in 91104672 on Windows x64. On the same 4,096-buffer CPU benchmark, equal-size teardown fell from 6.36 ms to 0.13–0.15 ms, replacing 4 KiB registrations with 2 KiB fell from 12.58–12.68 ms to 0.102 ms, and largest-first teardown fell from 6.37 ms to 0.29–0.31 ms. The two CPU-only registry tests passed. The new code also matched an exhaustive reference across 6,000 mutations and 18,000 lookups, including a covering buffer behind 96 siblings.

One trade-off for maintainers: with 4,096 distinct sizes, fetching the maximum from the tree costs ~6 ns per scattered hit (47 ns vs 41 ns with a cached maximum). At one size the difference was ~1 ns. Both variants used the same size-index heap. The original teardown concern is addressed. Synthetic registry timings only, 11 samples in each of two opposite-order runs. AI-assisted with Codex Astra 6.2 High.

<!-- greyfinch-sync:Marvisak/VIctory:review-comment:4713620062 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2096#discussion_r4713620062). Originally posted by [Desamodeth](https://github.com/Desamodeth) on 2026-11-26T21:48:53Z. **Code review location:** `crates/victory-gpu/src/shadow.rs`; line 831 ~~~~diff @@ -783,10 +783,57 @@ struct Entry { shadow: Option<Arc<Shadow>>, } +struct Buffers { + map: BTreeMap<(u64, usize), Entry>, + /// Maximum registered buffer size in `map`, bounding backward scans on misses. + max_size: u64, +} + +impl Buffers { + const fn new() -> Self { + Self { + map: BTreeMap::new(), + max_size: 0, + } + } + + fn insert(&mut self, resource: usize, start: u64, len: u64) { + if let Some(prev) = self.map.insert( + (start, resource), + Entry { + end: start + len, + shadow: None, + }, + ) && prev.end - start == self.max_size + && len < self.max_size + { + self.recompute_max_size(); + } + self.max_size = self.max_size.max(len); + } + + fn remove(&mut self, resource: usize, start: u64) -> Option<Entry> { + let removed = self.map.remove(&(start, resource))?; + if removed.end - start == self.max_size { + self.recompute_max_size(); + } + Some(removed) + } + + fn recompute_max_size(&mut self) { + self.max_size = self + .map + .iter() + .map(|(&(start, _), e)| e.end - start) + .max() + .unwrap_or(0); + } +} ~~~~ --- Verified the fix in `91104672` on Windows x64. On the same 4,096-buffer CPU benchmark, equal-size teardown fell from 6.36 ms to 0.13–0.15 ms, replacing 4 KiB registrations with 2 KiB fell from 12.58–12.68 ms to 0.102 ms, and largest-first teardown fell from 6.37 ms to 0.29–0.31 ms. The two CPU-only registry tests passed. The new code also matched an exhaustive reference across 6,000 mutations and 18,000 lookups, including a covering buffer behind 96 siblings. One trade-off for maintainers: with 4,096 distinct sizes, fetching the maximum from the tree costs ~6 ns per scattered hit (47 ns vs 41 ns with a cached maximum). At one size the difference was ~1 ns. Both variants used the same size-index heap. The original teardown concern is addressed. Synthetic registry timings only, 11 samples in each of two opposite-order runs. AI-assisted with Codex Astra 6.2 High.
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/2096:upstream-pr/2096'
git switch 'upstream-pr/2096'

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/2096'
git switch 'upstream-pr/2096'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2096'
git switch 'upstream-pr/2096'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2096'
git switch 'main'
git merge --squash 'upstream-pr/2096'
git switch 'main'
git merge --ff-only 'upstream-pr/2096'
git switch 'main'
git merge 'upstream-pr/2096'
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!2094
No description provided.