GPU: replace O(N^2) unmapped page lookup in Tracked::take_split with linear merge #3154
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T10:27:34Z.
Summary
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.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T11:10:46Z.
Review: APPROVED
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).
Imported from Marvisak/VIctory. Originally posted by rezioliver-collab on 2026-11-26T18:01:41Z.
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.
Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T21:54:18Z.
NVIDIA full-suite run, to go with the reports above by Dukestar69, since none of them names a GPU run. Tested exact head
467fc21(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.split_runs_merges_mapped_and_unmapped_in_linear_time.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.