runtime: add O(1) envelope fast path and explicit wrap to title_texture_refresh (RT-TITLE-TEXTURE-REFRESH-ENVELOPE-AND-WRAP) #2012
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2012"
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 ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T18:06:51Z.
Claim:
RT-TITLE-TEXTURE-REFRESH-ENVELOPE-AND-WRAP(claim comment#7170422103on #1608).Problem
In
runtime/src/title_texture_refresh.h:title_write_overlaps()always executedstd::upper_boundbefore checkingbegin >= end,writes.empty(), or whether[begin, end)falls outside the merged dirty envelope[writes.front().first, writes.back().second)— paying binary search overhead for thousands of unaffected waiting textures on every refresh pass.merge_title_writes()unconditionally invokedstd::sorteven on empty/single-entry or already-sorted write-range lists.poll_title_textures()incrementedcursor = address + 1, relying on implicit unsigned wrap ifaddress == UINT64_MAX.Fix
title_write_overlaps()on empty/inverted queries, outside-envelope ranges (end <= writes.front().first || begin >= writes.back().second), and single-range merges before falling back tostd::upper_bound.merge_title_writes()on 0/1-element inputs and skipstd::sortwhen already ordered.poll_title_textures()cursor wrap atUINT64_MAXexplicit (address == UINT64_MAX ? 0u : address + 1u).title_texture_refresh(runtime/test/title_texture_refresh_test.cpp).Benchmark (
clang++ -std=c++20 -O2, bit-exact A/B, 20,000 waiting textures x 2,000 passes)154.67 ms->18.72 ms(8.26x faster)43.08 ms->21.48 ms(2.01x faster)merge_title_writes()on 256 already-sorted ranges (50,000 calls):17.72 ms->12.48 ms(1.42x faster)Verification
runtime/test/title_texture_refresh_test.cppcleanly under:clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werrorclang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werrorclang++ -std=c++20 -O2 -Wall -Wextra -Werrorpython3 -I scripts/check_no_game_data.py runtime/src/title_texture_refresh.h runtime/test/title_texture_refresh_test.cpp runtime/CMakeLists.txtandpython3 -I tests/test_text_write_line_endings.py: all passed.Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T18:07:05Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-27T20:48:04Z.
Profile M data point with #1705 and #2012 applied together (RTX 4070 SUPER 12 GB, NVIDIA 621.01, Windows 11). Counts only. AI-assisted (Claude Code).
The
texturessubmit phase (Device::refresh_title_textures) after 900 s, means per submission:Not a one-variable A/B: G1d also changed
LEONIDA_KEYBOARD_PAD(always -> 1),LEONIDA_CAPTURE_LIMIT(40 -> 80) and ran on caches one run warmer, and the two pull requests are not separated. One run each, PROVISIONAL; refuted if the same tree without the two pull requests also shows tens of ms. Not run: #1705's new case ind3d12_existing_heap_test, because that test file does not compile in this local stack for an unrelated earlier merge;title_texture_refresh_test(#2012) passes.