perf(relinker): stream scans and reuse executable buffers #5116
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5116"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by sanxchep on 2026-10-13T12:09:49Z.
What
Stream the relinker's instruction scan through a visitor instead of materializing every decoded match. The syscall scanner retains only its bounded 64-instruction lookback for inline-stub detection; call-site resolution decodes once. Move the input ELF buffer through the conversion pipeline and avoid copying the text section when unused-symbol filtering is disabled. The behavior is generic to relinker inputs and contains no Kena-specific paths.
Tested
Hardware: Intel Core i9-13900H (14 cores / 20 threads), 32 GiB RAM, Intel Iris Xe and NVIDIA GeForce RTX 4070 Laptop GPU. Ubuntu 24.04, Linux 7.0.0-38-generic, GCC 13.3.0. This is a CPU-only conversion benchmark; neither GPU was used.
Build and automated checks: Release relinker-only build with
ANYPS5_RELINKER_ONLY=ONandBUILD_TESTING=ON; 149/149 CTest cases passed on this branch.python3 tools/check_conventions.py --base origin/mainandgit diff --check origin/main...HEADpassed.Undeclared Game name: same 171,748,944-byte input ELF and 36 bundled modules, default Linux conversion, five paired sequential runs on the same machine. Measured with
/usr/bin/time; elapsed seconds and maximum resident set size (KiB):Median elapsed time fell 35.5% and peak RSS 63.0%. Baseline was clean
mainat84e2a8c0b; relinker sources were unchanged between that revision and this PR's base14036cb0e. The complete default Linux output, including all 36 converted modules, was byte-identical between baseline and PR. Theunused-filter=1output was also byte-identical (10.88 s / 1,688,192 KiB baseline; 10.42 s / 1,509,596 KiB PR, one run). Windows and macOS cross-target conversions with bundled modules skipped produced byte-identical outputs; they were generated on Linux, not executed on those hosts.APS5 frame traces do not apply to this pre-execution CLI conversion; the paired
/usr/bin/timemeasurements above are the performance evidence. The converted Interactive Program was not run for this PR, so no InteractivePlay or frame-rate claim is made. No Interactive Program files are included in the change.Checklist
main; no other open PR found implementing this scanner and buffer optimizationImported from boykopovar/AnyPS5. Originally posted by AaravMehta-07 on 2026-10-13T12:23:01Z.
I have a separate, locally tested correctness fix that rejects
ET_RELinputs before executable conversion. It adds a guard at the start ofRelinkerPipeline::Relinkplus a Linux-output CLI regression; it does not change buffer ownership or scanning.Your current signature/initialization hunk touches the same insertion point. Could this PR go first, with my guard rebased onto it afterward? I will hold submission until the order is agreed or this refactor merges. The guard follows the ELF GABI distinction between relocatable objects and executable images, and the new test fails without it. The current standalone suite passes 144/144 locally on Windows.
This investigation, patch and comment are AI-assisted. No title runtime or performance result is claimed.
Imported from boykopovar/AnyPS5. Originally posted by sanxchep on 2026-10-13T12:50:19Z.
Thanks for checking. Your ET_REL guard sounds independent of the scanning and buffer changes, and the shared Relink hunk should be straightforward to rebase. Please feel free to submit your fix as a separate PR and note the overlap. If this PR lands first, you can rebase onto it; if yours lands first, I’ll rebase this one.
Imported from boykopovar/AnyPS5. Originally posted by AaravMehta-07 on 2026-10-13T12:57:55Z.
Thanks for coordinating. The separate ET_REL guard is submitted as #5148, with the shared hunk and our rebasing agreement explicitly documented. Neither change depends semantically on the other; I will rebase promptly if your refactor merges first.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T01:51:03Z.
Review: COMMENTED
I checked this against
mainand it looks good to me. The RSS drop is what I'd expect from no longer keeping every decodedInstructionMatchfor a 170 MB input.The points I checked:
ConstantSyscallNumberlooks backSYSCALL_NUMBER_LOOKBACK(8) instructions. The inline-stub matchers look back at most 42 bytes, which is at most 42 instructions.step < recent.countis the same bound as the oldstep <= syscallIndex.textSectionis still filled whenever something reads it. Only the two filter levels andCompactPlt(level 2) read it. Call-site resolution for the registry goes throughexecutableSegments.executableSegments.empty()is equivalent to the oldtextSection.empty()test, because empty segments are never added.TakeBytes. Onmain,Conversion::Convertonly handselfReaderto the pipeline, andRelinkResultholds copies, so nothing reads the reader afterTakeBytes().ripRelativeDispOffsetaccepts the same encodings as the two predicates it replaces.FF /2–/6takes any REX,8Bneeds REX.W, and both need mod=00, rm=101. The newCallSiteResolverTestscases cover the REX variants.One small difference: the
Syscallsprogress stage now reports only once, at the end. The per-4096-instruction updates are gone, so a progress display showsDecodemoving and thenSyscallsjumping to done. The total work is the same, so this is cosmetic. It might still be worth one start report so the stage appears./usr/bin/timepairs plus byte-identical outputs are the right evidence for a CLI conversion; frame traces don't apply here.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T03:05:25Z.
Conflicts with main in
RelinkerPipeline.cppsince #5148 added theET_RELcheck at the top ofRelink; please rebase and keep that check.Imported from boykopovar/AnyPS5. Originally posted by sanxchep on 2026-10-14T05:42:57Z.
done
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:23:57Z.
Checked the streamed scan against the old code: the 64-entry window covers
SYSCALL_NUMBER_LOOKBACK(8) and the 42-byte SDK inline stubs,step < recent.countmatches the oldstep <= syscallIndex, andripRelativeDispOffsetis the old FF/mov64 checks merged with the same conditions.textSectionis only read by unused-filter levels 1/2 andCompactPlt. TheET_RELcheck from #5148 is kept. relinker build and ctest (128/128) are green, relinker CI green on linux/windows/macos; merging once the full Windows build passes.