Heap: dynamic slot search over a bitset, a word of 64 taken or free slots per step #1719

Open
101Leafy wants to merge 2 commits from upstream-pr/1719 into main
101Leafy commented 2026-11-28 23:43:23 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 101Leafy on 2026-11-28T23:43:23Z.


The search for a run of free dynamic descriptor slots walked the taken flags one slot at a time over a Vec, so with a busy heap every table that asked for slots could step through most of the ring before it found a run or gave up.

The taken flags are now a bitset, and the search looks at a word of 64 slots per step: a word that is all taken or all free is passed over at once, and trailing_zeros finds where the next free or taken slot starts. It finds the same run as before, from the cursor on and then from the start up to cursor + n - 1, and release counts the slots it gives back the same way. A test checks it against the old slot by slot search on random fills.

There is no switch since nothing changes but the time the search takes.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5545727846 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1719). Originally posted by [101Leafy](https://github.com/101Leafy) on 2026-11-28T23:43:23Z. --- The search for a run of free dynamic descriptor slots walked the taken flags one slot at a time over a Vec<bool>, so with a busy heap every table that asked for slots could step through most of the ring before it found a run or gave up. The taken flags are now a bitset, and the search looks at a word of 64 slots per step: a word that is all taken or all free is passed over at once, and trailing_zeros finds where the next free or taken slot starts. It finds the same run as before, from the cursor on and then from the start up to cursor + n - 1, and release counts the slots it gives back the same way. A test checks it against the old slot by slot search on random fills. There is no switch since nothing changes but the time the search takes.
stokeer commented 2026-11-29 01:27:28 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by stokeer on 2026-11-29T01:27:28Z.


This breaks the diagnostics build (cargo build --profile diag -p victory --features diagnostics):

error[E0599]: no method named `get` found for struct `taken::Taken` in the current scope
    --> crates\victory-gpu\src\descriptor\host.rs:2206:79

slot_story in descriptor/host.rs is built with diagnostics and calls Taken::get, which this PR makes #[cfg(test)]. Making it available to both fixes it:

#[cfg(any(test, feature = "diagnostics"))]
pub(crate) fn get(&self, at: usize) -> Option<bool> {

Measured on a Ryzen 7 5700 + RTX 3060 Ti 8 GB (merged on f9dfb76f with seven other open PRs): no frame-time change in the prologue cell, ~53 ms against ~51 ms without them.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7248794431 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1719#issuecomment-7248794431). Originally posted by [stokeer](https://github.com/stokeer) on 2026-11-29T01:27:28Z. --- This breaks the diagnostics build (`cargo build --profile diag -p victory --features diagnostics`): ``` error[E0599]: no method named `get` found for struct `taken::Taken` in the current scope --> crates\victory-gpu\src\descriptor\host.rs:2206:79 ``` `slot_story` in `descriptor/host.rs` is built with `diagnostics` and calls `Taken::get`, which this PR makes `#[cfg(test)]`. Making it available to both fixes it: ```rust #[cfg(any(test, feature = "diagnostics"))] pub(crate) fn get(&self, at: usize) -> Option<bool> { ``` Measured on a Ryzen 7 5700 + RTX 3060 Ti 8 GB (merged on f9dfb76f with seven other open PRs): no frame-time change in the prologue cell, ~53 ms against ~51 ms without them.
amazedturnip commented 2026-11-29 05:38:46 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by amazedturnip on 2026-11-29T05:38:46Z.


Tested on 9800X3D + RTX 5070 Ti 16 GB across 20+ min sessions + full GPU unit suite. Dynamic bitset slot search ran cleanly with zero heap allocation or slot-reuse issues.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7251376031 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1719#issuecomment-7251376031). Originally posted by [amazedturnip](https://github.com/amazedturnip) on 2026-11-29T05:38:46Z. --- Tested on 9800X3D + RTX 5070 Ti 16 GB across 20+ min sessions + full GPU unit suite. Dynamic bitset slot search ran cleanly with zero heap allocation or slot-reuse issues.
101Leafy commented 2026-11-29 06:44:33 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 101Leafy on 2026-11-29T06:44:33Z.


Thanks, fixed in b6e1546053: Taken::get is now built for diagnostics too, as you suggested.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7252040511 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1719#issuecomment-7252040511). Originally posted by [101Leafy](https://github.com/101Leafy) on 2026-11-29T06:44:33Z. --- Thanks, fixed in b6e1546053: `Taken::get` is now built for `diagnostics` too, as you suggested.
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/1719:upstream-pr/1719'
git switch 'upstream-pr/1719'

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/1719'
git switch 'upstream-pr/1719'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1719'
git switch 'upstream-pr/1719'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1719'
git switch 'main'
git merge --squash 'upstream-pr/1719'
git switch 'main'
git merge --ff-only 'upstream-pr/1719'
git switch 'main'
git merge 'upstream-pr/1719'
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
trustno1-coder/VIctory-NVIDIA!1719
No description provided.