GPU: replace O(N^2) unmapped page lookup in Tracked::take_split with linear merge #3156
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3156
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3156"
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?
@reeledMarek on GitHub · 2026-11-26 10:27 UTC · original
reeledMarek:fix/gpu-watch-take-split-linear-merge→main· +43 −10 · 1 files · 1 commits · openSummary
Tracked::take_split(crates/victory-gpu/src/watch.rs), bothpages(fromBTreeSet::range) andunmapped(appended inwholeorder byprotect_noting) are strictly ascending, yet the run-splitting loop calledunmapped.contains(&p)(O(N)) inside an O(N) loop overpages— O(N^2) on large sparse/placeholder reservations.split_runs(&pages, &unmapped, from, to)using an O(N) two-pointer merge cursor over the two sorted slices.split_runs_merges_mapped_and_unmapped_in_linear_timecovering interleaved mapped/unmapped pages, clamped boundaries, and a 16,384-page (1 GiB) sparse reservation.@Dukestar69 on GitHub · 2026-11-26 11:10 UTC · original · approved these changes
Verified against
origin/main(63bcca4):cargo test -p victory-gpu --lib watch:: -- --test-threads=1: 16/16 passed (includingsplit_runs_merges_mapped_and_unmapped_in_linear_time).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly replaces the O(N^2) unmapped-page lookup in
Tracked::take_splitwith a linear merge.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@rezioliver-collab on GitHub · 2026-11-26 18:01 UTC · original
The density of unmapped pages made a large difference to the cost of splitting runs on Apple M1. In the same 16,384-page address span, I varied only which listed pages were unmapped.
I compared the run-splitting loop from
63bcca43withsplit_runsfrom467fc21c, compiled as native CPU kernels with Rust 1.98.1 atopt-level=3. Both received borrowed lists. Every nineteenth page was omitted from the input list, and the first and last byte ranges were clipped. Times are medians of 12 alternating pairs and cover splitting only.Across spans of 256, 4,096 and 16,384 pages, both implementations returned identical copy and zero byte ranges. I also expanded each result back into page numbers and checked it against the expected mapped and unmapped pages.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.