GameInput: binary-search retained readings #3684

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3684 into main
andrewpozdnakov7-jpg commented 2026-11-28 06:19:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T06:19:49Z.


GetNextReading and GetPreviousReading scanned every retained reading while holding the GameInput state mutex. Each device's history is already ordered by timestamp and sequence. This finds its nearest eligible reading with a binary search, then chooses among those candidates in the existing device and sequence order.

The regression test checks forward and backward traversal across two wrapped histories with shared timestamps. Eleven GameInput tests, strict HLE Clippy and the 191-file asset policy passed on Windows.

An optimized CPU fixture using the old and new search code matched all 49,872 generated queries. Median search time over 11 alternating runs was 521 to 114 ns at 32 readings per device and 3,535 to 166 ns at 256. This measures the search with synthetic inputs. It excludes locking, host polling and game frame time.

The history capacity and eviction rules stay the same in this PR. The 256-entry measurement is relevant to #3105.

Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5537402814 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3684). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T06:19:49Z. --- GetNextReading and GetPreviousReading scanned every retained reading while holding the GameInput state mutex. Each device's history is already ordered by timestamp and sequence. This finds its nearest eligible reading with a binary search, then chooses among those candidates in the existing device and sequence order. The regression test checks forward and backward traversal across two wrapped histories with shared timestamps. Eleven GameInput tests, strict HLE Clippy and the 191-file asset policy passed on Windows. An optimized CPU fixture using the old and new search code matched all 49,872 generated queries. Median search time over 11 alternating runs was 521 to 114 ns at 32 readings per device and 3,535 to 166 ns at 256. This measures the search with synthetic inputs. It excludes locking, host polling and game frame time. The history capacity and eviction rules stay the same in this PR. The 256-entry measurement is relevant to #3105. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit. AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-28 06:22:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T06:22:30Z.


Windows CI passed at d10b61e, including Clippy on both build configurations and the repository test job. The 49,872 synthetic comparisons and the lookup timings in the description apply to this head. The combined 256-entry history also passed all 13 GameInput tests. Combined results on #3105.

The next step is maintainer review.

Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding this change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7235254053 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3684#issuecomment-7235254053). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T06:22:30Z. --- [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/46116093972/job/140890164976) passed at `d10b61e`, including Clippy on both build configurations and the repository test job. The 49,872 synthetic comparisons and the lookup timings in the description apply to this head. The combined 256-entry history also passed all 13 GameInput tests. [Combined results on #3105](https://github.com/Marvisak/VIctory/pull/3105#issuecomment-7235249999). The next step is maintainer review. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding this change into another commit. AI-assisted with OpenAI Codex.
cloph-dsp commented 2026-11-28 10:43:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-28T10:43:06Z.


Independent local verification (Windows, Rust 1.100.0/MSVC, no game data):

  • PR #3684 at head d10b61ef92450f8744a750b382c4a280f70c36c8, base/parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • cargo test --locked -p victory-hle --lib -- modules::gameinput::tests::relative_readings_walk_wrapped_histories_with_tied_timestamps --exact --test-threads=1 --quiet → 1 passed, 0 failed, 152 filtered, exit 0.
  • git grep -F for the test name on the base returned no match (test is new on this PR); git diff --check 63bcca4 HEAD clean (1 file, +73/-15).
  • Used a per-worktree CARGO_TARGET_DIR (never shared) with CARGO_BUILD_JOBS=2.
  • Only the named synthetic test was replayed; full workspace suite and clippy were not run locally.
  • GPU/driver: N/A (CPU-only GameInput history test). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7238076478 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3684#issuecomment-7238076478). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T10:43:06Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #3684 at head `d10b61ef92450f8744a750b382c4a280f70c36c8`, base/parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - `cargo test --locked -p victory-hle --lib -- modules::gameinput::tests::relative_readings_walk_wrapped_histories_with_tied_timestamps --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 152 filtered, exit 0. - `git grep -F` for the test name on the base returned no match (test is new on this PR); `git diff --check 63bcca4 HEAD` clean (1 file, +73/-15). - Used a per-worktree `CARGO_TARGET_DIR` (never shared) with `CARGO_BUILD_JOBS=2`. - Only the named synthetic test was replayed; full workspace suite and clippy were not run locally. - GPU/driver: N/A (CPU-only GameInput history test). No game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3684:upstream-pr/3684'
git switch 'upstream-pr/3684'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3684'
git switch 'upstream-pr/3684'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3684'
git switch 'upstream-pr/3684'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3684'
git switch 'main'
git merge --squash 'upstream-pr/3684'
git switch 'main'
git merge --ff-only 'upstream-pr/3684'
git switch 'main'
git merge 'upstream-pr/3684'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
Marvisak/VIctory!3684
No description provided.