perf(relinker): return the collected instructions as a sorted vector #12282

Merged
JJenkx merged 5 commits from upstream-pr/12282 into main 2026-11-03 08:09:11 +00:00
JJenkx commented 2026-10-28 07:08:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-28T07:08:55Z.


What

CodeInstructionCollector::Collect returned its instruction addresses as a std::set. After #12154 it already holds them sorted and unique in a std::vector, so building the set added one heap node per instruction (millions on a large title) and nothing else. Its consumers only walk the result in order and binary search it.

Collect now returns that vector. Each user searches it as before, now with std::lower_bound and std::binary_search:

  • the instruction-overlap check inside Collect;
  • WindowsTlsBuilder and MacOsImage, which lower_bound to each code segment and walk forward;
  • the two ConversionTests membership checks.

The set of instructions and its order are unchanged.

Tested

Windows follow-up (2026-11-02): exact head 17979bdcbb and base main 93dbd0f82a, WinLibs GCC 15.2.0 UCRT r7 Release: 560/560 registered tests pass on each. Six alternating Goat Simulator 3 executable conversions per arm give medians 28.84 s on main and 16.52 s on this PR, with identical full output-tree hashes. This is one offline conversion workload, not title runtime evidence; see the full follow-up. The offline performance-report rule remains awaiting maintainer clarification in discussion #12358.

Current-main refresh (2026-11-01): linear head 17979bdcbb123db20af0dc7a47de0b98de38a1a5 on main 93dbd0f82aea. Main's incremental ExtendControlFlowGraph and byte-per-offset reached state are retained. The two prerequisite commits are the actual refreshed #12154 ancestry. Main's new initializer-array fixture now compares the ordered result as a vector. Linux x86-64, GCC 16.2.1, Ninja Release, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON: rebuilt relinker and all registered tests, 557/557 CTests pass; conventions and whitespace pass. Historical platform and performance reports below remain pinned to their stated commits; no new conversion timing or runtime gain is claimed.

Current qualification (2026-10-28)

@rooklz Fixed the pessimizing move in c7a46a7dfb991c9ec2e9da4a35045bcd6bb33577: return instructionList; permits NRVO and retains the implicit move when elision is unavailable. This is the only changed source line on the previous head.

Linux GCC 16.2.1 Release, relinker-only: a fresh build and all 373/373 CTests pass, with zero skips or failures. A separate Clang syntax check with -Wall -Wextra -Werror=pessimizing-move fails on the old statement and passes without warnings on this source. Conventions, whitespace and current-main merge preview pass.

Your macOS output-differential and test results remain attributed to the earlier head. No fresh macOS/Windows or speed measurement is claimed. The separate offline performance-report format question remains awaiting maintainers in discussion #12358; this warning fix does not clear that gate.

Source pins, reviewed patch/proofs, builds, controls, logs and JUnit, SHA-256 438ebb3ddb04bbedc39fb1b53e5d04b2a222831a55edb9004c076133b054d7ce.

Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, -DANYPS5_RELINKER_ONLY=ON.

  • Tests: all 372 relinker CTests pass in each of 3 runs at this head (BUILD_TESTING=ON).
  • Conversion time: #12154's head ad732ce0ec against this branch on it. Each ran relinker --windows --skip-sce-module --registry <eboot.elf> app.exe on four titles' executables, alternating, 3 rounds, wall time in ms:
title (eboot size) #12154 this PR median change app.exe sha256 (identical on both)
PPSA20423 (30 MB) 6268, 5956, 6101 5382, 5295, 5141 −13.2% 62c8241f…
PPSA13934 (32 MB) 6204, 6216, 6173 5483, 5291, 5358 −13.6% 0b1db4e7…
PPSA07923 (156 MB) 28068, 27947, 29980 24911, 48857, 26371 −6.0% 6465a4b2…
PPSA34008 (209 MB) 34544, 34931, 34538 31001, 37562, 31191 −9.7% f2f65cf7…

app.registry.json is byte-identical too in every round. The two bold rounds are outliers from machine-wide stalls on this host during this session; another relinker CTest run took 374 s instead of the usual 40 s, timing out unrelated Python tests too. They pull the large-title medians toward zero. Without them, PPSA07923 averages 25.6 s against the base median of 28.1 s (−8.6%), and PPSA34008 31.1 s against 34.5 s (−10.0%).

A separate run on main + #12154 + #12203 + #12270 measured the same change at −15% to −18% (PPSA20423 4.6 → 3.9 s, PPSA07923 22.7 → 19.1 s, PPSA34008 21.6 → 17.7 s), with identical output.

This measures conversion only, not anything at game run time. MacOsImage.cpp compiles in this Windows build, but I haven't run a macOS conversion.

Current refresh source proofs and unedited test logs, SHA-256 083d2668903c75794f1b3295acd852e3dd5bd106a6c2f30256aa518f7925a023.

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
  • 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 (#12154 is merged; historical stack and measurements remain pinned above)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5046629352 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12282). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-28T07:08:55Z. --- ### What `CodeInstructionCollector::Collect` returned its instruction addresses as a `std::set`. After #12154 it already holds them sorted and unique in a `std::vector`, so building the set added one heap node per instruction (millions on a large title) and nothing else. Its consumers only walk the result in order and binary search it. `Collect` now returns that vector. Each user searches it as before, now with `std::lower_bound` and `std::binary_search`: - the instruction-overlap check inside `Collect`; - `WindowsTlsBuilder` and `MacOsImage`, which `lower_bound` to each code segment and walk forward; - the two `ConversionTests` membership checks. The set of instructions and its order are unchanged. ### Tested **Windows follow-up (2026-11-02):** exact head `17979bdcbb` and base main `93dbd0f82a`, WinLibs GCC 15.2.0 UCRT r7 Release: 560/560 registered tests pass on each. Six alternating Goat Simulator 3 executable conversions per arm give medians 28.84 s on main and 16.52 s on this PR, with identical full output-tree hashes. This is one offline conversion workload, not title runtime evidence; see [the full follow-up](https://github.com/boykopovar/AnyPS5/pull/12282#issuecomment-6571198982). The offline performance-report rule remains awaiting maintainer clarification in discussion #12358. **Current-main refresh (2026-11-01):** linear head `17979bdcbb123db20af0dc7a47de0b98de38a1a5` on main `93dbd0f82aea`. Main's incremental `ExtendControlFlowGraph` and byte-per-offset reached state are retained. The two prerequisite commits are the actual refreshed #12154 ancestry. Main's new initializer-array fixture now compares the ordered result as a vector. Linux x86-64, GCC 16.2.1, Ninja Release, `ANYPS5_RELINKER_ONLY=ON`, `BUILD_TESTING=ON`: rebuilt relinker and all registered tests, **557/557 CTests pass**; conventions and whitespace pass. Historical platform and performance reports below remain pinned to their stated commits; no new conversion timing or runtime gain is claimed. <!-- codex-review-refresh-20261028-repeat-pr12282 --> **Current qualification (2026-10-28)** @rooklz Fixed the pessimizing move in `c7a46a7dfb991c9ec2e9da4a35045bcd6bb33577`: `return instructionList;` permits NRVO and retains the implicit move when elision is unavailable. This is the only changed source line on the previous head. Linux GCC 16.2.1 Release, relinker-only: a fresh build and all **373/373 CTests pass**, with zero skips or failures. A separate Clang syntax check with `-Wall -Wextra -Werror=pessimizing-move` fails on the old statement and passes without warnings on this source. Conventions, whitespace and current-main merge preview pass. Your macOS output-differential and test results remain attributed to the earlier head. No fresh macOS/Windows or speed measurement is claimed. The separate offline performance-report format question remains awaiting maintainers in [discussion #12358](https://github.com/boykopovar/AnyPS5/discussions/12358); this warning fix does not clear that gate. [Source pins, reviewed patch/proofs, builds, controls, logs and JUnit](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr12282-c7a46a7d-linux-review-20261028-repeat.tar.gz), SHA-256 `438ebb3ddb04bbedc39fb1b53e5d04b2a222831a55edb9004c076133b054d7ce`. Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, `-DANYPS5_RELINKER_ONLY=ON`. - **Tests:** all 372 relinker CTests pass in each of 3 runs at this head (`BUILD_TESTING=ON`). - **Conversion time:** #12154's head `ad732ce0ec` against this branch on it. Each ran `relinker --windows --skip-sce-module --registry <eboot.elf> app.exe` on four titles' executables, alternating, 3 rounds, wall time in ms: | title (eboot size) | #12154 | this PR | median change | `app.exe` sha256 (identical on both) | |---|---|---|---|---| | PPSA20423 (30 MB) | 6268, 5956, 6101 | 5382, 5295, 5141 | −13.2% | `62c8241f…` | | PPSA13934 (32 MB) | 6204, 6216, 6173 | 5483, 5291, 5358 | −13.6% | `0b1db4e7…` | | PPSA07923 (156 MB) | 28068, 27947, 29980 | 24911, **48857**, 26371 | −6.0% | `6465a4b2…` | | PPSA34008 (209 MB) | 34544, 34931, 34538 | 31001, **37562**, 31191 | −9.7% | `f2f65cf7…` | `app.registry.json` is byte-identical too in every round. The two bold rounds are outliers from machine-wide stalls on this host during this session; another relinker CTest run took 374 s instead of the usual 40 s, timing out unrelated Python tests too. They pull the large-title medians toward zero. Without them, PPSA07923 averages 25.6 s against the base median of 28.1 s (−8.6%), and PPSA34008 31.1 s against 34.5 s (−10.0%). A separate run on `main` + #12154 + #12203 + #12270 measured the same change at −15% to −18% (PPSA20423 4.6 → 3.9 s, PPSA07923 22.7 → 19.1 s, PPSA34008 21.6 → 17.7 s), with identical output. This measures conversion only, not anything at game run time. `MacOsImage.cpp` compiles in this Windows build, but I haven't run a macOS conversion. [Current refresh source proofs and unedited test logs](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr12282-17979bdc-rebase-linux-20261101.tar.gz), SHA-256 `083d2668903c75794f1b3295acd852e3dd5bd106a6c2f30256aa518f7925a023`. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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) - [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 (#12154 is merged; historical stack and measurements remain pinned above) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-28 08:52:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T08:52:48Z.

Review: CHANGES_REQUESTED


The vector conversion is well covered by the relinker tests and the conversion-time measurements; I found no output-order or membership issue in the diff. I cannot approve the perf-labeled PR under the repository’s current rule, though: it still has perf numbers missing, and the required same-title/same-scene aps5-summary.jsonl lines, attached traces, and trace_digest.py output are absent. Please add the report required by the current CONTRIBUTING.md/performance form, or get the repository rule clarified for this non-runtime relinker benchmark before removing that gate. The current CI relinker matrix passes; author-reported tests are 372 CTests x3.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5680011728 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12282#pullrequestreview-5680011728). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T08:52:48Z. **Review:** CHANGES_REQUESTED --- The vector conversion is well covered by the relinker tests and the conversion-time measurements; I found no output-order or membership issue in the diff. I cannot approve the `perf`-labeled PR under the repository’s current rule, though: it still has `perf numbers missing`, and the required same-title/same-scene `aps5-summary.jsonl` lines, attached traces, and `trace_digest.py` output are absent. Please add the report required by the current `CONTRIBUTING.md`/performance form, or get the repository rule clarified for this non-runtime relinker benchmark before removing that gate. The current CI relinker matrix passes; author-reported tests are 372 CTests x3.
rooklz commented 2026-10-28 11:33:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T11:33:46Z.

Review: COMMENTED


macOS evidence for the parts the body says are untested (MacOsImage.cpp was only compiled on Windows).

Setup: macOS arm64, Apple clang, Ninja, Release, -DANYPS5_RELINKER_ONLY=ON. Head df77e4df6d (stacked on #12154 ad732ce0ec) against main 3a40945e62.

  • Tests: ctest 362/362 pass at this head. check_conventions.py --base upstream/main passes, and git merge-tree against main is clean.

  • Output differential, including the macOS writer: I relinked 5 homebrew payload ELFs (ftpsrv, websrv, kstuff, elfldr, prosperotrace; none are game titles) with --skip-syscall-check --skip-sce-module --registry in the Linux, --windows and --macos modes, using both main and this head. All 15 pairs exit 0 and the outputs are byte-identical. WriteMacOsImage → ScanTls and WindowsPePatcher → WindowsTlsBuilder::Build both call Collect unconditionally, so the 10 Windows/macOS runs go through the changed lower_bound callers. None of these inputs has a PT_TLS, so the TLS-access loop bodies themselves are only exercised by the CTests.

  • Mutants on the stack:

    • Killed: dropping the final sort (48 CTests fail, 6/6 corpus outputs differ) and dropping the final unique (40 fail, 2/6 differ).
    • Survived: dropping the staticTargets sort or unique, the decoded[offset] bitmap dedupe, and the new reachable address outside its section throw.

    The survivors make sense: the dedupes only affect speed because of the final sort+unique, and the throw is a defensive guard. They come from #12154's commits, so I'm noting them here rather than asking for changes.

One fix requested (new warning): CodeInstructionCollector.cpp:584 return std::move(instructionList); triggers clang -Wpessimizing-move ("moving a local object in a return statement prevents copy elision"). main's version of the file is warning-free under -Wall -Wextra. return instructionList; gets NRVO and a guaranteed move, and with it the file compiles with 0 warnings. The const auto& instructions = instructionList; alias doesn't block this.

The perf evidence question is still open (#12358); I'm not taking a position on it.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5681941420 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12282#pullrequestreview-5681941420). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-28T11:33:46Z. **Review:** COMMENTED --- macOS evidence for the parts the body says are untested (`MacOsImage.cpp` was only compiled on Windows). **Setup:** macOS arm64, Apple clang, Ninja, Release, `-DANYPS5_RELINKER_ONLY=ON`. Head `df77e4df6d` (stacked on #12154 `ad732ce0ec`) against `main` `3a40945e62`. - **Tests:** `ctest` 362/362 pass at this head. `check_conventions.py --base upstream/main` passes, and `git merge-tree` against `main` is clean. - **Output differential, including the macOS writer:** I relinked 5 homebrew payload ELFs (ftpsrv, websrv, kstuff, elfldr, prosperotrace; none are game titles) with `--skip-syscall-check --skip-sce-module --registry` in the Linux, `--windows` and `--macos` modes, using both `main` and this head. All 15 pairs exit 0 and the outputs are byte-identical. `WriteMacOsImage` → `ScanTls` and `WindowsPePatcher` → `WindowsTlsBuilder::Build` both call `Collect` unconditionally, so the 10 Windows/macOS runs go through the changed `lower_bound` callers. None of these inputs has a PT_TLS, so the TLS-access loop bodies themselves are only exercised by the CTests. - **Mutants on the stack:** - Killed: dropping the final `sort` (48 CTests fail, 6/6 corpus outputs differ) and dropping the final `unique` (40 fail, 2/6 differ). - Survived: dropping the `staticTargets` sort or `unique`, the `decoded[offset]` bitmap dedupe, and the new `reachable address outside its section` throw. The survivors make sense: the dedupes only affect speed because of the final sort+unique, and the throw is a defensive guard. They come from #12154's commits, so I'm noting them here rather than asking for changes. **One fix requested (new warning):** `CodeInstructionCollector.cpp:584` `return std::move(instructionList);` triggers clang `-Wpessimizing-move` ("moving a local object in a return statement prevents copy elision"). `main`'s version of the file is warning-free under `-Wall -Wextra`. `return instructionList;` gets NRVO and a guaranteed move, and with it the file compiles with 0 warnings. The `const auto& instructions = instructionList;` alias doesn't block this. The `perf` evidence question is still open (#12358); I'm not taking a position on it. AI-assisted: yes (Claude Code)
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!12282
No description provided.