Skip to content

Spread aligned sparse tile keys across hash buckets - #230

Merged
ivall merged 2 commits into
ivall:mainfrom
AliceWood:perf/sparse-tile-hash-eaa36b6
Nov 23, 2026
Merged

ivall merged 2 commits into
ivall:mainfrom
AliceWood:perf/sparse-tile-hash-eaa36b6

Conversation

@AliceWood

Copy link
Copy Markdown
Contributor

The sparse tile map keys its entries by 64 KiB-aligned virtual addresses. Hashing a single address multiplies it by an odd constant, so its low 16 bits remain zero. For maps with at most 65,536 buckets, every aligned address then starts its lookup in the same bucket. Rotating the 64-bit hash right by 23 puts varying bits in the bucket index and moves bits 16 through 22 into the high seven bits used for the table’s short hash.

CPU measurements

Workload on 6,720 tiles Baseline Patched Speedup
16 passes over every tile, 107,520 successful lookups 16.649 ms 0.170 ms 98.2×
Individual tile removals, empty pending-clear queue 2.441 ms 0.657 ms 3.7×
Individual tile removals, one pending clear per tile 4,280.407 ms 32.430 ms 132.0×

The harness compiled each revision's hasher, tile map types and decommit_tiles with Rust 1.97.1 and -O on a Ryzen 9 9950X3D running Windows x64. It initialized consecutive tile addresses starting at 4 GiB, excluded setup from the timer, and checked the remaining mappings, clear queue, and reclaimed tile count. The table gives medians from seven processes per variant, alternating which variant ran first.

The measurements were taken against eaa36b6 and its patched source. Both source blocks extracted by the benchmark are byte-identical between that baseline and 0cd0a53, and between the previously benchmarked patch and this PR at 5424468. The third row includes the repeated clear-queue scan in these revisions. PR #203 changes where that scan runs. The first two rows measure operations with an empty queue or direct map lookups.

Tests

The regression test hashes 256 consecutive tile addresses and checks that at least half the low-byte bucket indices are used. The original hash used just one. On 5424468, the focused sparse suite passed 10 tests and ignored one timing benchmark. The full library suite reported 584 passed, zero failed, and 20 ignored. The RTX 4080 reported two tests skipped for lack of native wave64. Optional game sample variables were unset, and one optional system XGameRuntime test reported a skip.

cargo +1.97.1 test --locked --offline -p xcl --lib -- --test-threads=4 --nocapture

Retail observations

GTA VI build 1.0.2.1 ran on the Ryzen 9 9950X3D and RTX 4080 in fresh offline Windows Sandbox guests using the Series S profile. Both XCL builds used empty guest caches and the same timer around XMemMapPhysicalPagesScatter, including lock wait. Each run completed six calls of at least 1,024 pages, including two successful 6,720-page calls. The table follows launch order on 0cd0a53.

Run 6,720-page call median Present calls in activity samples Game process
Baseline 1 375.219 ms 158 Exited on breakpoint
Patched 1 455.886 ms 165 Exited on breakpoint
Patched 2 398.081 ms 163 Exited on breakpoint
Baseline 2 460.554 ms 147 Breakpoint logged, launcher still running at 210 s

The patch was slower in the first pair and faster in the second. All four runs logged 0x80000003 at game_scarlett_master.exe+0xcc2834, the same offset reported in #156. Present counts sum the available two-second activity samples. Visible frames were not measured. An earlier six-run comparison on eaa36b6 also reached that breakpoint every time. These runs show no consistent retail loading improvement from the hash change.

@ivall
ivall merged commit 8c5d16e into ivall:main Nov 23, 2026
@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Merged (main 0f34407). Checked on an RX 9070 (RDNA4) with 6 PRs merged together on main d4f17ca: cargo build --workspace && cargo test --workspace -- --test-threads=4 - 611 unit tests passed, 0 failed (20 ignored), the integration and e2e tests passed; and the retail game still reaches its first menu at 30 fps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants