perf(tools): scan trace slices once for the slowest frames #28916

Open
JJenkx wants to merge 1 commit from upstream-pr/28916 into main
JJenkx commented 2026-12-04 16:28:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-12-04T16:28:54Z.


What

The slowest-frame section of trace_digest.py used to scan all captured slices for each requested frame. Walk the sorted slices once per thread and accumulate only their intersections with the selected frames. The report keeps its frame ranking, clipped contributions and tie order.

Tested

Linux 7.3.6 x86-64, Python 3.14.10. All 195 tests in python3 -B -m unittest discover -s tools/tests -p 'test_trace*.py' pass. The new test checks a slice spanning two selected frames with an unselected frame between them, exact-edge exclusions and tied slice totals. Compared the complete digest against main in 750 generated cases and verified byte-identical default JSON and 30-frame Markdown output on a completed trace.

Median digest computation time over six alternating runs per version on the same parsed Smurfs village trace, with 280 frame intervals and 850,316 slices. Main was 82a605ad2c23. Parsing and rendering were outside the timed interval.

Slow frames requested Main This change
0 0.664 s 0.677 s
1 0.760 s 0.769 s
5 (default) 1.215 s 0.767 s
30 3.978 s 0.806 s

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Summary by CodeRabbit

  • Bug Fixes
    • Slice totals for selected slowest frames now reflect only the portion of each slice that overlaps each frame, including when slices span gaps or extend beyond the selected frame range.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5650256485 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28916). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-12-04T16:28:54Z. --- ### What The slowest-frame section of `trace_digest.py` used to scan all captured slices for each requested frame. Walk the sorted slices once per thread and accumulate only their intersections with the selected frames. The report keeps its frame ranking, clipped contributions and tie order. ### Tested Linux 7.3.6 x86-64, Python 3.14.10. All 195 tests in `python3 -B -m unittest discover -s tools/tests -p 'test_trace*.py'` pass. The new test checks a slice spanning two selected frames with an unselected frame between them, exact-edge exclusions and tied slice totals. Compared the complete digest against main in 750 generated cases and verified byte-identical default JSON and 30-frame Markdown output on a completed trace. Median digest computation time over six alternating runs per version on the same parsed [Smurfs village trace](https://github.com/boykopovar/AnyPS5/discussions/8158#discussioncomment-20140953), with 280 frame intervals and 850,316 slices. Main was `82a605ad2c23`. Parsing and rendering were outside the timed interval. | Slow frames requested | Main | This change | | ---: | ---: | ---: | | 0 | 0.664 s | 0.677 s | | 1 | 0.760 s | 0.769 s | | 5 (default) | 1.215 s | 0.767 s | | 30 | 3.978 s | 0.806 s | ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt/) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Slice totals for selected slowest frames now reflect only the portion of each slice that overlaps each frame, including when slices span gaps or extend beyond the selected frame range. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Plyxen commented 2026-12-04 16:55:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-04T16:55:04Z.

Review: APPROVED


Verified head 772780c4d3 on Windows 11 with Python 3.13.7, applied to a copy of tools/ (plus docs/run-report-fixtures) from main 2fbf8b4391.

  • python -m unittest discover -s tools/tests -p 'test_trace*.py': 195 tests OK (1 skipped). Main has 194 OK.
  • Equivalence: I generated 3,000 random traces (1–4 threads, 0–60 slices each with zero, grid-aligned and random durations, 0–25 presents, worst of 0, 1, 2, 5 or 30) and compared digest(...)["slowest_frames"] between main and this PR. There were 0 differences. 2,171 cases had slices in their slowest frames and 846 had tied slice totals, so tie order is covered.
  • Timing on a synthetic trace (8 threads, 200,000 slices, 280 frames, median of 3): worst=1 0.092 s vs 0.095 s, worst=5 0.138 s vs 0.098 s, worst=30 0.481 s vs 0.106 s. Same shape as the table in the PR.

Reading it: the single pass depends on each thread's slices being sorted by start time, which Trace.__init__ already guarantees, and on the frames being consecutive, non-overlapping intervals from Trace.frames. The per-frame Counter is filled in the same thread and slice order as before, so most_common breaks ties the same way.

Not run: Linux or a real capture.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6193074901 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28916#pullrequestreview-6193074901). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-12-04T16:55:04Z. **Review:** APPROVED --- Verified head 772780c4d3 on Windows 11 with Python 3.13.7, applied to a copy of `tools/` (plus `docs/run-report-fixtures`) from `main` `2fbf8b4391`. - `python -m unittest discover -s tools/tests -p 'test_trace*.py'`: 195 tests OK (1 skipped). Main has 194 OK. - Equivalence: I generated 3,000 random traces (1–4 threads, 0–60 slices each with zero, grid-aligned and random durations, 0–25 presents, `worst` of 0, 1, 2, 5 or 30) and compared `digest(...)["slowest_frames"]` between main and this PR. There were 0 differences. 2,171 cases had slices in their slowest frames and 846 had tied slice totals, so tie order is covered. - Timing on a synthetic trace (8 threads, 200,000 slices, 280 frames, median of 3): `worst=1` 0.092 s vs 0.095 s, `worst=5` 0.138 s vs 0.098 s, `worst=30` 0.481 s vs 0.106 s. Same shape as the table in the PR. Reading it: the single pass depends on each thread's slices being sorted by start time, which `Trace.__init__` already guarantees, and on the frames being consecutive, non-overlapping intervals from `Trace.frames`. The per-frame `Counter` is filled in the same thread and slice order as before, so `most_common` breaks ties the same way. Not run: Linux or a real capture. AI-assisted: yes (Claude Code)
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/28916:upstream-pr/28916'
git switch 'upstream-pr/28916'

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/28916'
git switch 'upstream-pr/28916'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/28916'
git switch 'upstream-pr/28916'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/28916'
git switch 'main'
git merge --squash 'upstream-pr/28916'
git switch 'main'
git merge --ff-only 'upstream-pr/28916'
git switch 'main'
git merge 'upstream-pr/28916'
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
boykopovar/AnyPS5!28916
No description provided.