[PR #2065] Cache repeated title VA alias lookups (RT-TITLE-VA-POSITIVE-LOOKUP-CACHE) #2073

Open
opened 2026-11-26 21:19:56 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2065
Author: @alexandersato0830
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: codex/title-va-positive-cache


📝 Commits (1)

  • 83e9133 Cache repeated title VA alias lookups per thread

📊 Changes

2 files changed (+87 additions, -15 deletions)

View changed files

📝 runtime/src/title_va_alias.h (+41 -15)
📝 runtime/test/title_va_alias_test.cpp (+46 -0)

📄 Description

Claimed in the coordination issue as: RT-TITLE-VA-POSITIVE-LOOKUP-CACHE

Depends on: #1699 (overlapping test include hunk; the runtime change applies independently).

What and why

Repeated lookups in one title VA range acquire a shared lock and search the map each time. Cache one positive mapping per thread after two uncached lookups in the same range. A cache hit checks range bounds, the table's invalidation counter and its instance identity. Other requests still query the live map. Original finding

The draft records the lookup tradeoff so it can be evaluated with runtime traces. The retail lookup mix and frame-time impact remain unmeasured.

Tested

  • Native Windows 11, MSVC 19.51, on public main 490f5b9 plus this patch. All ten targeted CTests passed, including title_va_alias, d3d12_title_va, shadow and geometry views, the window cap, and descriptor copy and table rebound on/off paths. The new regression checks range bounds, deletion, replacement across threads, and reuse of the same storage for a new table. Removing either guard made the test fail.
  • Ryzen 9 7950X3D, single pinned thread, MSVC /O2. One executable compared the original and patched header, interleaving five timed samples per case. Each sample made five passes over 524,288 precomputed inputs. The tests used 32, 1,024 and 4,096 64 KiB ranges. Hot queries moved to a new range every 1,000 lookups, and mixed queries replaced every fifth lookup with a uniformly random one. The random controls included all mapped addresses and 50% addresses in gaps.
  • Across shader_va and range_of, the median hot lookups took 66–77% less time and the mixed lookups 34–39% less time. Random cases took 1.6–10.5% more time, an increase of 1.2–2.3 ns per query in this run. Most of the relative penalty occurred at 32 ranges. The benchmark compared returned addresses on the same input stream.
  • Verified git diff --check and the source-only check.

GPUs tested: NVIDIA RTX 4080, driver 621.01, Windows 11.

AI-assisted: yes.

  • Based on current main.
  • One topic.
  • Uses source and synthetic fixtures.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2065 **Author:** [@alexandersato0830](https://github.com/alexandersato0830) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `codex/title-va-positive-cache` --- ### 📝 Commits (1) - [`83e9133`](https://github.com/ubiquitarianism/leonida/commit/83e91333650d426fd11d46c46655972eb5de4157) Cache repeated title VA alias lookups per thread ### 📊 Changes **2 files changed** (+87 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/title_va_alias.h` (+41 -15) 📝 `runtime/test/title_va_alias_test.cpp` (+46 -0) </details> ### 📄 Description Claimed in the coordination issue as: [RT-TITLE-VA-POSITIVE-LOOKUP-CACHE](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7171881642) Depends on: #1699 (overlapping test include hunk; the runtime change applies independently). ### What and why Repeated lookups in one title VA range acquire a shared lock and search the map each time. Cache one positive mapping per thread after two uncached lookups in the same range. A cache hit checks range bounds, the table's invalidation counter and its instance identity. Other requests still query the live map. [Original finding](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164354183) The draft records the lookup tradeoff so it can be evaluated with runtime traces. The retail lookup mix and frame-time impact remain unmeasured. ### Tested - Native Windows 11, MSVC 19.51, on public main `490f5b9` plus this patch. All ten targeted CTests passed, including `title_va_alias`, `d3d12_title_va`, shadow and geometry views, the window cap, and descriptor copy and table rebound on/off paths. The new regression checks range bounds, deletion, replacement across threads, and reuse of the same storage for a new table. Removing either guard made the test fail. - Ryzen 9 7950X3D, single pinned thread, MSVC `/O2`. One executable compared the original and patched header, interleaving five timed samples per case. Each sample made five passes over 524,288 precomputed inputs. The tests used 32, 1,024 and 4,096 64 KiB ranges. Hot queries moved to a new range every 1,000 lookups, and mixed queries replaced every fifth lookup with a uniformly random one. The random controls included all mapped addresses and 50% addresses in gaps. - Across `shader_va` and `range_of`, the median hot lookups took **66–77% less time** and the mixed lookups **34–39% less time**. Random cases took **1.6–10.5% more time**, an increase of **1.2–2.3 ns per query** in this run. Most of the relative penalty occurred at 32 ranges. The benchmark compared returned addresses on the same input stream. - Verified `git diff --check` and the source-only check. GPUs tested: NVIDIA RTX 4080, driver 621.01, Windows 11. AI-assisted: yes. - [x] Based on current `main`. - [x] One topic. - [x] Uses source and synthetic fixtures. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#2073
No description provided.