runtime: early-exit pending_through and cache semaphore completions in RetireTickets #2025

Open
github-bot wants to merge 1 commit from github-bot/gh-2025 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 18:28 UTC · original
IlyassRS3:perf/rt-retire-tickets-early-break-and-sem-cache → main · +106 −2 · 2 files · 1 commits · open

Coordination item: RT-RETIRE-TICKETS-EARLY-BREAK-AND-SEM-CACHE (claimed on #1608).

Why

  1. RetireTickets::pending_through(ticket) scanned the entire pending_ deque even though normal record() calls arrive in non-decreasing ticket order (as documented at the top of retire_tickets.h). Under deletion-queue backpressure (VulkanBackend::wait_retire_ticket(old_ticket)), scanning thousands of newer in-flight submissions wastes mutex-held CPU time under submit_mutex_.
  2. RetireTickets::completed(query) invoked the caller's Vulkan semaphore query (vkGetSemaphoreCounterValue) for every non-idle pending entry, even when a previous entry in the same pass already confirmed an equal or higher timeline value on that semaphore.

Changes

  • runtime/src/retire_tickets.h:
    • Track monotonic_ (automatically reset to true when pending_ drains, cleared if an out-of-order ticket < pending_.back().ticket is recorded) so pending_through(ticket) returns immediately when ticket < pending_.front().ticket and breaks as soon as entry.ticket > ticket in the monotonic case, while preserving full-scan exactness for out-of-order tickets.
    • Cache up to 8 (semaphore, highest_confirmed_value) entries on the stack inside completed(query) so subsequent entries in the same pass with front.value <= confirmed skip redundant query() calls.
  • runtime/test/retire_tickets_test.cpp: add tests for per-pass confirmed-value caching, >8-semaphore cache eviction, non-monotonic pending_through() fallback, monotonic reset after drain, and cutoff-before-front early return.

Verification

  • AI-assisted: yes (Antigravity agent by Google DeepMind).
  • GPUs tested: none (CPU-only unit tests & benchmark on macOS arm64).
  • Compiled and ran runtime/test/retire_tickets_test.cpp with clang++ -std=c++20 -Wall -Wextra -Werror:
    • ASan+UBSan (-O1 -g -fsanitize=address,undefined): PASS.
    • TSan (-O1 -g -fsanitize=thread): PASS.
    • Release (-O2): PASS.
  • A/B -O2 benchmark (50,000 calls to pending_through(16) on 4,096 pending submissions across 3 queues):
    • main: 137.223 ms (acc=2400000)
    • this branch: 8.417 ms (acc=2400000, 16.30× faster, bit-exact).
  • python3 -I scripts/check_no_game_data.py runtime/src/retire_tickets.h runtime/test/retire_tickets_test.cpp: clean.
  • python3 -I tests/test_text_write_line_endings.py: 3/3 OK.
**@⁠IlyassRS3** on GitHub · 2026-11-25 18:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2025) `IlyassRS3:perf/rt-retire-tickets-early-break-and-sem-cache` → `main` · +106 −2 · 2 files · 1 commits · open Coordination item: `RT-RETIRE-TICKETS-EARLY-BREAK-AND-SEM-CACHE` (claimed on #1608). ### Why 1. `RetireTickets::pending_through(ticket)` scanned the entire `pending_` deque even though normal `record()` calls arrive in non-decreasing ticket order (as documented at the top of `retire_tickets.h`). Under deletion-queue backpressure (`VulkanBackend::wait_retire_ticket(old_ticket)`), scanning thousands of newer in-flight submissions wastes mutex-held CPU time under `submit_mutex_`. 2. `RetireTickets::completed(query)` invoked the caller's Vulkan semaphore query (`vkGetSemaphoreCounterValue`) for every non-idle pending entry, even when a previous entry in the same pass already confirmed an equal or higher timeline value on that semaphore. ### Changes - `runtime/src/retire_tickets.h`: - Track `monotonic_` (automatically reset to `true` when `pending_` drains, cleared if an out-of-order ticket `< pending_.back().ticket` is recorded) so `pending_through(ticket)` returns immediately when `ticket < pending_.front().ticket` and breaks as soon as `entry.ticket > ticket` in the monotonic case, while preserving full-scan exactness for out-of-order tickets. - Cache up to 8 `(semaphore, highest_confirmed_value)` entries on the stack inside `completed(query)` so subsequent entries in the same pass with `front.value <= confirmed` skip redundant `query()` calls. - `runtime/test/retire_tickets_test.cpp`: add tests for per-pass confirmed-value caching, >8-semaphore cache eviction, non-monotonic `pending_through()` fallback, monotonic reset after drain, and cutoff-before-front early return. ### Verification - AI-assisted: yes (Antigravity agent by Google DeepMind). - GPUs tested: none (CPU-only unit tests & benchmark on macOS arm64). - Compiled and ran `runtime/test/retire_tickets_test.cpp` with `clang++ -std=c++20 -Wall -Wextra -Werror`: - ASan+UBSan (`-O1 -g -fsanitize=address,undefined`): PASS. - TSan (`-O1 -g -fsanitize=thread`): PASS. - Release (`-O2`): PASS. - A/B `-O2` benchmark (50,000 calls to `pending_through(16)` on 4,096 pending submissions across 3 queues): - `main`: `137.223 ms` (`acc=2400000`) - this branch: `8.417 ms` (`acc=2400000`, **16.30× faster**, bit-exact). - `python3 -I scripts/check_no_game_data.py runtime/src/retire_tickets.h runtime/test/retire_tickets_test.cpp`: clean. - `python3 -I tests/test_text_write_line_endings.py`: 3/3 OK.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:15:07 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 18:28 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 18:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2025#pullrequestreview-6062887367) · **reviewed** 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2025/head:github-bot/gh-2025'
git switch 'github-bot/gh-2025'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2025'
git switch 'github-bot/gh-2025'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2025'
git switch 'github-bot/gh-2025'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2025'
git switch 'main'
git merge --squash 'github-bot/gh-2025'
git switch 'main'
git merge --ff-only 'github-bot/gh-2025'
git switch 'main'
git merge 'github-bot/gh-2025'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.