perf(relinker): reuse decoded control-flow instructions #18432

Open
bipinkrish wants to merge 1 commit from upstream-pr/18432 into main
bipinkrish commented 2026-11-11 14:13:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by bipinkrish on 2026-11-11T14:13:02Z.


What

Pass decoded x86 instruction metadata from the control-flow walk to CodeInstructionCollector. The collector reuses the decode for root discovery and retains the final instruction-boundary validation and lowest-address diagnostic ordering.

The overlap check found shared edits with #13716 at the include list and with #14107 at the control-flow call. Manual review of #10861 found a shared control-flow interface and collector loop. Those PRs change which code the collector reaches. This change reuses the decoded metadata after the walker reaches an instruction. The branches can merge independently, with a rebase if a shared edit lands first.

Tested

Ubuntu 24.04.4 LTS, Ryzen 7 7735HS, GCC 13.3, Release, -DANYPS5_RELINKER_ONLY=ON. Compared upstream 03522377c3f with 2c2563d23ed. Each row reports median wall time over 20 alternating pairs pinned to CPU 15. The CLI workloads use the same 2.55 MB compiler-generated ELF with many branches.

Workload Main ms Change ms Change
Collector, one million instructions 85.489 63.090 −26.2%
Windows relink 146.935 143.330 −2.5%
Windows relink with --function-symbol-roots 147.157 144.520 −1.8%
macOS relink 148.710 144.872 −2.6%

The million-instruction fixture went from 3,000,000 to 2,000,000 decoder calls. On the generated ELF, calls fell from 2,594,406 to 2,201,104. Both revisions found the same 409,686 instruction offsets and 32,769 roots. Every emitted PE and Mach-O matched its baseline byte for byte.

Both revisions passed the same 46 focused CTest cases covering conversion, control-flow graphs, code and data scanning, function-symbol roots, and Windows and macOS TLS. These measurements cover conversion on fixtures. Same-scene title captures are pending.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5260999842 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18432). Originally posted by [bipinkrish](https://github.com/bipinkrish) on 2026-11-11T14:13:02Z. --- ### What Pass decoded x86 instruction metadata from the control-flow walk to `CodeInstructionCollector`. The collector reuses the decode for root discovery and retains the final instruction-boundary validation and lowest-address diagnostic ordering. The overlap check found shared edits with #13716 at the include list and with #14107 at the control-flow call. Manual review of #10861 found a shared control-flow interface and collector loop. Those PRs change which code the collector reaches. This change reuses the decoded metadata after the walker reaches an instruction. The branches can merge independently, with a rebase if a shared edit lands first. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 24.04.4 LTS, Ryzen 7 7735HS, GCC 13.3, Release, `-DANYPS5_RELINKER_ONLY=ON`. Compared upstream `03522377c3f` with `2c2563d23ed`. Each row reports median wall time over 20 alternating pairs pinned to CPU 15. The CLI workloads use the same 2.55 MB compiler-generated ELF with many branches. | Workload | Main ms | Change ms | Change | | --- | ---: | ---: | ---: | | Collector, one million instructions | 85.489 | 63.090 | −26.2% | | Windows relink | 146.935 | 143.330 | −2.5% | | Windows relink with `--function-symbol-roots` | 147.157 | 144.520 | −1.8% | | macOS relink | 148.710 | 144.872 | −2.6% | The million-instruction fixture went from 3,000,000 to 2,000,000 decoder calls. On the generated ELF, calls fell from 2,594,406 to 2,201,104. Both revisions found the same 409,686 instruction offsets and 32,769 roots. Every emitted PE and Mach-O matched its baseline byte for byte. Both revisions passed the same 46 focused CTest cases covering conversion, control-flow graphs, code and data scanning, function-symbol roots, and Windows and macOS TLS. These measurements cover conversion on fixtures. Same-scene title captures are pending. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
MarcZX10 commented 2026-11-12 14:26:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T14:26:07Z.

Review: COMMENTED


Reviewed decode reuse in the control-flow walk — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

Head 2c2563d23ed37a092978256ccc17eaa6dca30946, base main. No build and no compile in this pass. Source-level review of the diff and of the code around it, read through the repository reader at the head.

python3 repo_read.py search ExtendControlFlowGraph
python3 repo_read.py cat core/relinker/relinker/src/analysis/UnusedNidFilter/ControlFlowGraph.cpp 60 130
python3 repo_read.py cat core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp 520 590
python3 repo_read.py search "struct DecodedInstructionInfo"
python3 repo_read.py search "file-backed" core/relinker/relinker/tests

Results

Check Result Note
Changed hunks and callers passed 3 of 3 files, at the head
Lowest-address failure order passed kept by the first-failure check
Tests for the deferred failure path failed none assert it
Build and CTest not run no build in this pass
Author's timings and byte-match claims not run author-reported
Commands and output

The commands are listed under What I ran. Output is not quoted here.

Findings

Blocking

None.

Non-blocking

  • core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp:577: the deferred-failure path (lines 566–578) has no test. Nothing under core/relinker/relinker/tests asserts the messages "branch target is not executable and file-backed" or "fall-through is not executable and file-backed". A change that rethrows the first failure in walk order instead of the lowest address would not be caught by the tree's tests.

Sources

Not verified

  • Build, the 46 CTest cases, the byte-identical PE and Mach-O output, and the timings: author-reported, not run here.
  • Performance evidence: the description says the same-scene title captures are pending. The repository's performance report requirements apply once they are attached.
  • "Based on current main": I compared against the base in the manifest and did not check live main on GitHub.
  • core/relinker/relinker/include/relinker/analysis/UnusedNidFilter/IControlFlowGraph.hpp was read as diff hunks only, not as full text. The forward declaration of Codegen::DecodedInstructionInfo matches its struct definition.
  • Compile-level details (lambda captures, default arguments, the using alias) are checked by reading only.

To get this to a good state

Nothing is required.

Optional: add a test where two instructions fail analysis in reverse address order and check that the lower address is reported. Attach the same-scene title captures that the performance form asks for.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5876098128 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18432#pullrequestreview-5876098128). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-12T14:26:07Z. **Review:** COMMENTED --- # Reviewed decode reuse in the control-flow walk — no blocking findings Nothing blocks this; the points below are optional. **What I ran** Head `2c2563d23ed37a092978256ccc17eaa6dca30946`, base `main`. No build and no compile in this pass. Source-level review of the diff and of the code around it, read through the repository reader at the head. ```sh python3 repo_read.py search ExtendControlFlowGraph python3 repo_read.py cat core/relinker/relinker/src/analysis/UnusedNidFilter/ControlFlowGraph.cpp 60 130 python3 repo_read.py cat core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp 520 590 python3 repo_read.py search "struct DecodedInstructionInfo" python3 repo_read.py search "file-backed" core/relinker/relinker/tests ``` **Results** | Check | Result | Note | | --- | --- | --- | | Changed hunks and callers | passed | 3 of 3 files, at the head | | Lowest-address failure order | passed | kept by the first-failure check | | Tests for the deferred failure path | failed | none assert it | | Build and CTest | not run | no build in this pass | | Author's timings and byte-match claims | not run | author-reported | <details> <summary>Commands and output</summary> The commands are listed under **What I ran**. Output is not quoted here. </details> **Findings** **Blocking** None. **Non-blocking** - `core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp:577`: the deferred-failure path (lines 566–578) has no test. Nothing under `core/relinker/relinker/tests` asserts the messages "branch target is not executable and file-backed" or "fall-through is not executable and file-backed". A change that rethrows the first failure in walk order instead of the lowest address would not be caught by the tree's tests. **Sources** - Deferred failure and lowest-address rethrow: https://github.com/boykopovar/AnyPS5/blob/2c2563d23ed37a092978256ccc17eaa6dca30946/core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp#L566-L580 - The walker calls the visitor once per newly reached instruction: https://github.com/boykopovar/AnyPS5/blob/2c2563d23ed37a092978256ccc17eaa6dca30946/core/relinker/relinker/src/analysis/UnusedNidFilter/ControlFlowGraph.cpp#L97-L116 **Not verified** - Build, the 46 CTest cases, the byte-identical PE and Mach-O output, and the timings: author-reported, not run here. - Performance evidence: the description says the same-scene title captures are pending. The repository's performance report requirements apply once they are attached. - "Based on current `main`": I compared against the base in the manifest and did not check live `main` on GitHub. - `core/relinker/relinker/include/relinker/analysis/UnusedNidFilter/IControlFlowGraph.hpp` was read as diff hunks only, not as full text. The forward declaration of `Codegen::DecodedInstructionInfo` matches its `struct` definition. - Compile-level details (lambda captures, default arguments, the `using` alias) are checked by reading only. **To get this to a good state** Nothing is required. Optional: add a test where two instructions fail analysis in reverse address order and check that the lower address is reported. Attach the same-scene title captures that the performance form asks for.
ligmaSec commented 2026-12-03 17:06:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T17:06:12Z.

Review: COMMENTED


In a Linux relinker-only build from this head, dynamic_segment and sce_code_extent passed. This head conflicts with current main in CodeInstructionCollector.cpp. Main now follows code addresses only when both the SCE and the other function inventories are empty. Preserve that condition when passing the decoded-instruction visitor into the current traversal.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6174573702 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18432#pullrequestreview-6174573702). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T17:06:12Z. **Review:** COMMENTED --- In a Linux relinker-only build from this head, `dynamic_segment` and `sce_code_extent` passed. This head conflicts with current main in `CodeInstructionCollector.cpp`. Main now follows code addresses only when both the SCE and the other function inventories are empty. Preserve that condition when passing the decoded-instruction visitor into the current traversal. AI-assisted: yes.
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/18432:upstream-pr/18432'
git switch 'upstream-pr/18432'

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