present: look up retained frame tokens by age #1198

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

@⁠Kadamitas on GitHub · 2026-11-24 20:02 UTC · original
Kadamitas:perf/retained-frame-token-lookup → main · +35 −37 · 1 files · 1 commits · open

Claimed in the coordination issue as direct lookup of retained FramePacer records.

What and why

Several FramePacer operations scan the same retained history to find one frame token. Tokens in that history are consecutive, so their age identifies a record directly. Use one bounded lookup for statistics, submission timing and retirement, preserving missing and expired token behavior and the existing lock.

Tested

  • Both existing upstream frame-pacer test paths passed before and after.
  • An independent boundary check verified null and expired tokens, the 64-record limit, and wraparound.
  • MSVC /O2 on Windows, five runs per version with two million presents and 250,000 statistics queries per run. Median CPU time fell from 95.3 to 41.3 ns per token. This measures the frame-pacer bookkeeping in isolation.

GPUs tested: N/A. The frame-pacer fixture uses a simulated clock.

AI-assisted: yes.

Checklist

  • Based on current main (6293c1c4f).
  • One topic.
  • No game data, keys or decryption.
**@⁠Kadamitas** on GitHub · 2026-11-24 20:02 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1198) `Kadamitas:perf/retained-frame-token-lookup` → `main` · +35 −37 · 1 files · 1 commits · open Claimed in the coordination issue as [direct lookup of retained FramePacer records](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14). ### What and why Several FramePacer operations scan the same retained history to find one frame token. Tokens in that history are consecutive, so their age identifies a record directly. Use one bounded lookup for statistics, submission timing and retirement, preserving missing and expired token behavior and the existing lock. ### Tested - Both existing upstream frame-pacer test paths passed before and after. - An independent boundary check verified null and expired tokens, the 64-record limit, and wraparound. - MSVC /O2 on Windows, five runs per version with two million presents and 250,000 statistics queries per run. Median CPU time fell from 95.3 to 41.3 ns per token. This measures the frame-pacer bookkeeping in isolation. GPUs tested: N/A. The frame-pacer fixture uses a simulated clock. AI-assisted: yes. ### Checklist - [x] Based on current `main` (`6293c1c4f`). - [x] One topic. - [x] No game data, keys or decryption.
Origin waits append consecutive tokens to the 64-record history. Index the matching record from the back and reuse it during present, statistics and retirement. Advance the issued counter only after appending succeeds, so a failed allocation cannot leave a hole in the history.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:42:36 +00:00
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 07:07 UTC · original

Reviewed 7b61143: built and ran runtime/test/frame_pacer_test.cpp (g++ -std=c++20) in the sandbox on PR, main, and PR-test-on-main — all pass, and a 70-frame differential probe (aging, repeated/stale/null/untokened presents, immediate, suspend/resume, uncapped) is byte-identical across this branch, base 58be9cdf, and origin/main, so the refactor is sound at its base. However, this branch conflicts in runtime/src/frame_pacer.h (main's test does not compile against it), and the age-index lookup cannot survive a rebase onto origin/main: records_ is no longer consecutive with tokens_->issued() because FrameTokenSource is shared with the device proxy (and unregistered current_origin_poll also issues tokens without recording). With the PR's lookup hand-applied onto main's header, an external token issue makes the pacer's own freshest record disappear (statistics(2) hr=0x1 count=0 vs main hr=0x0 [time=16000]), and statistics(4) / commit_present_token(4) bind token 2's record (time=16000 vs main 32000); the same shift occurs after suspend()/resume() + unregistered current_origin_poll without a shared source. Please rebase and keep Record::token in token_record_locked() (e.g., scan or std::lower_bound on the monotonic records_ deque) so lookup survives gaps while keeping the single-lookup cleanup, and add a regression test covering shared-source / poll gaps. AI-assisted review.
Recommendation: Fix first

**@⁠PierreEbele** on GitHub · 2026-11-25 07:07 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1198#issuecomment-7155507530) Reviewed 7b61143: built and ran `runtime/test/frame_pacer_test.cpp` (`g++ -std=c++20`) in the sandbox on PR, main, and PR-test-on-main — all pass, and a 70-frame differential probe (aging, repeated/stale/null/untokened presents, immediate, suspend/resume, uncapped) is byte-identical across this branch, base `58be9cdf`, and `origin/main`, so the refactor is sound at its base. However, this branch conflicts in `runtime/src/frame_pacer.h` (main's test does not compile against it), and the age-index lookup cannot survive a rebase onto `origin/main`: `records_` is no longer consecutive with `tokens_->issued()` because `FrameTokenSource` is shared with the device proxy (and unregistered `current_origin_poll` also issues tokens without recording). With the PR's lookup hand-applied onto main's header, an external token issue makes the pacer's own freshest record disappear (`statistics(2) hr=0x1 count=0` vs main `hr=0x0 [time=16000]`), and `statistics(4)` / `commit_present_token(4)` bind token 2's record (`time=16000` vs main `32000`); the same shift occurs after `suspend()`/`resume()` + unregistered `current_origin_poll` without a shared source. Please rebase and keep `Record::token` in `token_record_locked()` (e.g., scan or `std::lower_bound` on the monotonic `records_` deque) so lookup survives gaps while keeping the single-lookup cleanup, and add a regression test covering shared-source / poll gaps. AI-assisted review. **Recommendation:** Fix first
This pull request has changes conflicting with the target branch.
  • runtime/src/frame_pacer.h
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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