perf(relinker): reserve the reachable instruction set before the graph walk #12270

Merged
JJenkx merged 1 commit from upstream-pr/12270 into main 2026-11-02 13:36:29 +00:00
JJenkx commented 2026-10-28 06:20:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-28T06:20:12Z.


What

Reserve capacity for an initially empty reachable-address set in the compatibility buildGraph API, using a quarter of the input text size. A nonempty set keeps its existing capacity policy. Graph traversal and resulting addresses are unchanged.

Main now includes #13825, whose incremental byte-state API is used by CodeInstructionCollector; this reservation no longer affects that production hot path. The earlier conversion speedups below describe the old implementation and do not establish a current-main conversion or runtime improvement. The remaining compatibility-API benefit has not been remeasured.

Tested

Current-main refresh (2026-11-01): linear head ddbcfaa792deef1467ec4617a5949f66e818b713 on main 93dbd0f82aea. Main's incremental ExtendControlFlowGraph and byte-per-offset reached state are retained. 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. No new Windows, macOS, title or performance measurement.

Historical qualification, before #13825:

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

  • Tests: all 380 relinker CTests pass in each of 3 runs (BUILD_TESTING=ON).
  • Conversion time: main 0cd07dc4ab against this branch on it, both Release. Each ran relinker --windows --skip-sce-module --registry <eboot.elf> app.exe on four titles' executables, alternating main and this branch, 3 rounds, wall time in ms:
title (eboot size) main this PR median change app.exe sha256 (identical on both)
PPSA20423 (30 MB) 8511, 8409, 8335 7029, 6968, 6898 −17.1% 62c8241f…
PPSA13934 (32 MB) 8862, 8803, 8824 7431, 7385, 7344 −16.3% 0b1db4e7…
PPSA07923 (156 MB) 40357, 40380, 40339 31525, 31158, 31243 −22.6% 6465a4b2…
PPSA34008 (209 MB) 64019, 64242, 64212 47831, 47634, 47708 −25.7% f2f65cf7…

app.registry.json is byte-identical too in every round.

  • Peak memory: sampled every 100 ms. Peak private bytes are the same, 2,042 vs 2,045 MiB on PPSA34008 and 2,044 vs 2,044 MiB on PPSA07923. The conversion's peak happens elsewhere, so the reservation doesn't raise it.
  • Profile: found by sampling stacks of a PPSA07923 conversion with gdb, on main plus #12154 and #12203. Most samples were in CodeInstructionCollector::Collect and buildGraph, much of it in std::unordered_set insert and rehash. With both of those PRs applied, the same change takes PPSA07923 from 27.7 s to 22.8 s with identical output, so it adds to them rather than overlapping.

This measures conversion only, not anything at game run time. Those original measurements did not test Linux or macOS and do not apply to the current hot path.

Independent macOS follow-up: Apple clang/libc++, head 96bbd3af91 merged onto main 2227f13661, 378/378 CTests and byte-identical outputs/registries for nine homebrew conversions across 15 alternating rounds. Small-input speed differences and memory costs are reported separately; these are the reviewer's measurements: rooklz's report. The offline performance-report format remains awaiting maintainer guidance in discussion #12358.

Current refresh source proofs and unedited test logs, SHA-256 8c0931882d0f81671b3606f9714526651a605ffbb291bd9bfffb2480968a7d1f.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5046143070 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12270). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-28T06:20:12Z. --- ### What Reserve capacity for an initially empty reachable-address set in the compatibility `buildGraph` API, using a quarter of the input text size. A nonempty set keeps its existing capacity policy. Graph traversal and resulting addresses are unchanged. Main now includes #13825, whose incremental byte-state API is used by `CodeInstructionCollector`; this reservation no longer affects that production hot path. The earlier conversion speedups below describe the old implementation and **do not establish a current-main conversion or runtime improvement**. The remaining compatibility-API benefit has not been remeasured. ### Tested **Current-main refresh (2026-11-01):** linear head `ddbcfaa792deef1467ec4617a5949f66e818b713` on main `93dbd0f82aea`. Main's incremental `ExtendControlFlowGraph` and byte-per-offset reached state are retained. 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. No new Windows, macOS, title or performance measurement. **Historical qualification, before #13825:** Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, `-DANYPS5_RELINKER_ONLY=ON`. - **Tests:** all 380 relinker CTests pass in each of 3 runs (`BUILD_TESTING=ON`). - **Conversion time:** `main` `0cd07dc4ab` against this branch on it, both Release. Each ran `relinker --windows --skip-sce-module --registry <eboot.elf> app.exe` on four titles' executables, alternating `main` and this branch, 3 rounds, wall time in ms: | title (eboot size) | `main` | this PR | median change | `app.exe` sha256 (identical on both) | |---|---|---|---|---| | PPSA20423 (30 MB) | 8511, 8409, 8335 | 7029, 6968, 6898 | −17.1% | `62c8241f…` | | PPSA13934 (32 MB) | 8862, 8803, 8824 | 7431, 7385, 7344 | −16.3% | `0b1db4e7…` | | PPSA07923 (156 MB) | 40357, 40380, 40339 | 31525, 31158, 31243 | −22.6% | `6465a4b2…` | | PPSA34008 (209 MB) | 64019, 64242, 64212 | 47831, 47634, 47708 | −25.7% | `f2f65cf7…` | `app.registry.json` is byte-identical too in every round. - **Peak memory:** sampled every 100 ms. Peak private bytes are the same, 2,042 vs 2,045 MiB on PPSA34008 and 2,044 vs 2,044 MiB on PPSA07923. The conversion's peak happens elsewhere, so the reservation doesn't raise it. - **Profile:** found by sampling stacks of a PPSA07923 conversion with gdb, on `main` plus #12154 and #12203. Most samples were in `CodeInstructionCollector::Collect` and `buildGraph`, much of it in `std::unordered_set` insert and rehash. With both of those PRs applied, the same change takes PPSA07923 from 27.7 s to 22.8 s with identical output, so it adds to them rather than overlapping. This measures conversion only, not anything at game run time. Those original measurements did not test Linux or macOS and do not apply to the current hot path. <!-- codex-attributed-macos-review-20261028 --> Independent macOS follow-up: Apple clang/libc++, head `96bbd3af91` merged onto main `2227f13661`, 378/378 CTests and byte-identical outputs/registries for nine homebrew conversions across 15 alternating rounds. Small-input speed differences and memory costs are reported separately; these are the reviewer's measurements: [rooklz's report](https://github.com/boykopovar/AnyPS5/pull/12270#pullrequestreview-5682219024). The offline performance-report format remains awaiting maintainer guidance in [discussion #12358](https://github.com/boykopovar/AnyPS5/discussions/12358). [Current refresh source proofs and unedited test logs](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr12270-ddbcfaa7-rebase-linux-20261101.tar.gz), SHA-256 `8c0931882d0f81671b3606f9714526651a605ffbb291bd9bfffb2480968a7d1f`. ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-28 08:56:20 +00:00 (Migrated from github.com)

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

Review: COMMENTED


The reported conversion timings are directly relevant to this offline relinker change: paired runs on the same machine and inputs, alternating revisions, with identical output hashes and repeat counts. A game runtime capture and trace_digest.py cannot measure this pre-launch conversion, as you explain. However, CONTRIBUTING.md currently says PRs titled perf(...) need two valid aps5-summary.jsonl lines, and the automated label still marks perf numbers missing. I do not see a way to satisfy that runtime-specific format for this operation. I’m leaving this as a comment rather than requesting an irrelevant game capture; please get maintainer guidance on whether the rule has an offline-tool exception or what alternate report format they want. No code correctness issue found in the one-line reserve change, and the current relinker/ASan CI matrix passes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5680048921 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12270#pullrequestreview-5680048921). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T08:56:20Z. **Review:** COMMENTED --- The reported conversion timings are directly relevant to this offline relinker change: paired runs on the same machine and inputs, alternating revisions, with identical output hashes and repeat counts. A game runtime capture and `trace_digest.py` cannot measure this pre-launch conversion, as you explain. However, `CONTRIBUTING.md` currently says PRs titled `perf(...)` need two valid `aps5-summary.jsonl` lines, and the automated label still marks `perf numbers missing`. I do not see a way to satisfy that runtime-specific format for this operation. I’m leaving this as a comment rather than requesting an irrelevant game capture; please get maintainer guidance on whether the rule has an offline-tool exception or what alternate report format they want. No code correctness issue found in the one-line reserve change, and the current relinker/ASan CI matrix passes.
rooklz commented 2026-10-28 11:59:03 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Independent run on the platform the body lists as untested: macOS 26 arm64 (Apple clang, libc++), Release, -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON.

Setup. Head 96bbd3af91 merged onto current main 2227f13661 (clean; the diff against main is still this one line). I compared it with a main build from the same compiler and flags.

  • CTest: 378/378 pass on the merged head.
  • Reachability: buildGraph is present in the macOS binary (nm), so the walk runs here on libc++'s unordered_set and not only on libstdc++.
  • Conversion time: 3 homebrew payload ELFs (ftpsrv, kstuff, websrv; none are game titles) with --skip-syscall-check --skip-sce-module --registry, in all three output modes. 15 rounds, alternating which build runs first, median wall ms:
input mode main this PR change
ftpsrv (190 KB) linux 2.6 2.6 −1.4%
ftpsrv windows 6.3 6.1 −4.1%
ftpsrv macos 6.3 6.0 −4.4%
kstuff (1.5 MB) linux 7.1 7.1 0.0%
kstuff windows 45.7 41.0 −10.4%
kstuff macos 47.7 43.0 −9.9%
websrv (1.6 MB) linux 5.0 5.1 +1.4%
websrv windows 22.6 21.0 −7.4%
websrv macos 23.1 22.0 −5.0%
  • Output binaries and registry.json are byte-identical between main and this PR in all 9 cases, on every round.
  • The Linux-mode runs take a few ms, so they are within noise.
  • The gain carries over to libc++, which answers the "expect a similar gain there" line in the body. It is smaller than on the title-sized inputs in the body, as you'd expect for text sections this small.
  • Peak RSS (/usr/bin/time -l, --macos, 3 runs each): kstuff goes from 22.4–23.3 MiB to 24.1–24.2 MiB (about +1.8 MiB). websrv is unchanged (15.9 vs 15.9 MiB).
    • The codeSize / 4 reservation can be larger than the final reachable set, so on small inputs the bucket array shows up in the peak.
    • Your Windows title numbers show the peak sits elsewhere on large inputs. I can't measure titles here, so I'm only flagging this as a non-blocking observation.

No correctness concerns: one reserve guarded by empty(), walk order and outputs unchanged. I'm leaving this as a comment because the open question is the maintainers' perf-report format for offline tools (#12358), not the code.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5682219024 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12270#pullrequestreview-5682219024). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-28T11:59:03Z. **Review:** COMMENTED --- Independent run on the platform the body lists as untested: **macOS 26 arm64 (Apple clang, libc++)**, Release, `-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`. **Setup.** Head `96bbd3af91` merged onto current `main` `2227f13661` (clean; the diff against main is still this one line). I compared it with a `main` build from the same compiler and flags. - **CTest:** 378/378 pass on the merged head. - **Reachability:** `buildGraph` is present in the macOS binary (`nm`), so the walk runs here on libc++'s `unordered_set` and not only on libstdc++. - **Conversion time:** 3 homebrew payload ELFs (ftpsrv, kstuff, websrv; none are game titles) with `--skip-syscall-check --skip-sce-module --registry`, in all three output modes. 15 rounds, alternating which build runs first, median wall ms: | input | mode | `main` | this PR | change | |---|---|---|---|---| | ftpsrv (190 KB) | linux | 2.6 | 2.6 | −1.4% | | ftpsrv | windows | 6.3 | 6.1 | −4.1% | | ftpsrv | macos | 6.3 | 6.0 | −4.4% | | kstuff (1.5 MB) | linux | 7.1 | 7.1 | 0.0% | | kstuff | windows | 45.7 | 41.0 | −10.4% | | kstuff | macos | 47.7 | 43.0 | −9.9% | | websrv (1.6 MB) | linux | 5.0 | 5.1 | +1.4% | | websrv | windows | 22.6 | 21.0 | −7.4% | | websrv | macos | 23.1 | 22.0 | −5.0% | - Output binaries and `registry.json` are byte-identical between `main` and this PR in all 9 cases, on every round. - The Linux-mode runs take a few ms, so they are within noise. - The gain carries over to libc++, which answers the "expect a similar gain there" line in the body. It is smaller than on the title-sized inputs in the body, as you'd expect for text sections this small. - **Peak RSS** (`/usr/bin/time -l`, `--macos`, 3 runs each): kstuff goes from 22.4–23.3 MiB to 24.1–24.2 MiB (about +1.8 MiB). websrv is unchanged (15.9 vs 15.9 MiB). - The `codeSize / 4` reservation can be larger than the final reachable set, so on small inputs the bucket array shows up in the peak. - Your Windows title numbers show the peak sits elsewhere on large inputs. I can't measure titles here, so I'm only flagging this as a non-blocking observation. No correctness concerns: one `reserve` guarded by `empty()`, walk order and outputs unchanged. I'm leaving this as a comment because the open question is the maintainers' perf-report format for offline tools (#12358), not the code. 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!12270
No description provided.