[PR #2025] runtime: early-exit pending_through and cache semaphore completions in RetireTickets #2033

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

📋 Pull Request Information

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

Base: main ← Head: perf/rt-retire-tickets-early-break-and-sem-cache


📝 Commits (1)

  • cf5127e runtime: early-exit pending_through and cache semaphore completions in RetireTickets

📊 Changes

2 files changed (+106 additions, -2 deletions)

View changed files

📝 runtime/src/retire_tickets.h (+49 -2)
📝 runtime/test/retire_tickets_test.cpp (+57 -0)

📄 Description

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.

🔄 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/2025 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `perf/rt-retire-tickets-early-break-and-sem-cache` --- ### 📝 Commits (1) - [`cf5127e`](https://github.com/ubiquitarianism/leonida/commit/cf5127e811cde0d53cf6c3b262703dd00b9b5198) runtime: early-exit pending_through and cache semaphore completions in RetireTickets ### 📊 Changes **2 files changed** (+106 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/retire_tickets.h` (+49 -2) 📝 `runtime/test/retire_tickets_test.cpp` (+57 -0) </details> ### 📄 Description 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. --- <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#2033
No description provided.