perf(libkernel): resolve an APR path's directory once and find the file in its listing #11446
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11446"
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 noir39 on 2026-10-26T13:51:09Z.
What
sceKernelAprResolveFilepathsToIds*already takes each file's size from a listing of its directory (one directory read instead of one size query per path), but it still resolved every path throughResolvePath, which on Windows asks the file system for each file's attributes (GetFileAttributesWinResolveHostPath). An absolute path now resolves its directory once, cached by the guest directory, and the file is looked up in that directory's listing.The fast path is taken only when the listing has an entry whose on-disk name equals the guest's last component exactly. Everything else takes the full resolve as before, so
MatchNamesstill corrects the case and still reports an ambiguous name:E.binande.bin; the size query then also skips the listing);.,..or a separator, a last component containing\or:, a last component longer than 255 bytes, a path of 1024 bytes or more;app0.zar).The directory cache is dropped whenever a path alias changes: libc counts
AddPathAlias,RemovePathAlias,BlockPathAliasandAddPathProvidercalls (PathAliasGeneration_nid_no_patch), so a save-data mount point rebound to another save resolves into the new directory (the case @MarcZX10 found in the review of #10633, which this PR replaces: #10633 was closed by the open-PR limit and could not be reopened after the branch was rebased).Tested
Windows 11 Pro 26200, Ryzen 9 5950X, Samsung 980 NVMe, RTX 3080, WinLibs GCC 15.2.0 r7, branch rebased onto
mainf759e165d9.guest_apr_read_resolve(BUILD_TESTING=ON): absolute paths in one directory and a subdirectory; a name in other case than on disk (b.BINforB.bin); every resolved id is stat'ed (sceKernelAprGetFileStat) and read through aReadFilecommand; the same id for a path resolved again; a file created after its directory was listed; a missing file (error_index, size 0); a 256-byte name (reported missing); two names differing only in case, checked where the host file system keeps both; an alias rebound from one directory to another between two resolves of the same path.ctest -R "guest_apr|guest_ampr|savedata|guest_path|working_directory|guest_directory|realpath|app_archive|fopen_long": 45 of 45 pass;tools/check_conventions.pypasses.Start-up timing. The gain is before the title's first frame, outside the
aps5-summary.jsonlframe summaries, so this is the title's own timing of that phase, measured the same way for both builds:sceKernelAprResolveFilepathsToIds*: about 243,000 paths inResourcePool::GatherResourceFileInfo, which logs its own duration.mainf759e165d9and this branch on it.eboot.elf, the samerelinker.exeand the same save; onlylibs\was swapped, with itslibkernel.prxhash checked against the build.[shader-disk-cache]totals of at most 7 misses; the cold runs took 1:04 and 1:00 onmainwhile compiling about 2,000 shaders).GatherResourceFileInfo() tookmainf759e165d9e8ba6924a4An earlier series on
main4a6005955fgave 47.03 s, 46.82 s and 46.88 s.Raw log lines
Checklist
main(f759e165d9); no other open PR implements the same functions (tools/pr_overlap.py: no other open PR conflicts with these lines; the shared files it could not compare arelibkernel/CMakeLists.txt,libc/src/General.cppandlibc/include/General.hpp, which this PR touches only to add a test case and the alias counter)NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T14:04:30Z.
Review: CHANGES_REQUESTED
Current
mainis263fbcd2d3; this branch's merge base is6cd36e6517. I checked the merge directly:git merge-tree upstream/main upstream/pr-11446reports a content conflict incore/libs/tests/GuestAprRead.cpp. Please rebase onto currentmainand preserve the intervening APR test coverage before asking for a final review. The local focused build could not be configured because SDL2 development files are unavailable here, so I did not runguest_apr_read_tests; the 44/44 Windows test result in the description is author-reported.The PR is labeled
perf, but the requiredaps5-summary.jsonlbefore/after lines, attached traces andtools/trace_digest.pyoutput are absent. The title startup timings are useful, but the description says the standard frame summary does not cover this pre-first-frame phase. Please get maintainer direction on an accepted startup measurement format and attach that evidence (or otherwise resolve theperf numbers missingrequirement) before merge. I have not treated the timing log as a substitute for the prescribed report.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T16:22:04Z.
Review: CHANGES_REQUESTED
I rechecked exact head
e04cf056aca7against livemain518d36eaec0a. The priorGuestAprRead.cppmerge conflict is resolved, but the current merge base is1061954c7e55andmainhas since changedcore/libs/prx/libkernel/CMakeLists.txt, which this PR also modifies. Please sync to currentmain, preserve the added tests, and rerun the focused APR suite and conventions on the updated tree. The author-reported 44/44 run is on the older1061954c7base.The performance requirement also remains unresolved: the PR reports a startup improvement before the first present, outside the documented frame-trace window. I still do not see a valid same-title/same-scene main/change capture pair and digests. Please get maintainer direction on an accepted reproducible startup benchmark format (same machine, title, startup path, base/head and raw timings) or otherwise resolve the
perf numbers missingrequirement; I will not treat the current title log as the prescribed trace report.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-27T10:21:14Z.
Review: DISMISSED
Thanks, the alias invalidation (
PathAliasGeneration) looks right and its test covers it. Points to fix:Apr.cpp:151:hostDirectory / nameuses the guest's spelling, while_listedSizematches case-folded. On Linux (or a case-sensitive directory) with onlyB.binon disk,/apr_resolve/b.BINreturns size 5 but stores a host path that does not exist, so ReadFile andsceKernelAprGetFileStaton that id throw, andb.BIN/B.binget two ids. Main resolves viaMatchNamesand getsB.bin(or the ambiguity error). Keep the on-disk name from the listing and take the fast path only when it equals the guest's name; make the test read/statids[1].:145/:151run outsideResolvePathError: on Windows a non-UTF-8 name throwsfilesystem_error, and a directory that exists only inapp0.zarthrowsNotImplementedwhere main returns ENOENT. Fall back to the full resolve in both cases.Resolve's checks: a name containing:(D:foo.bindrops the root name throughoperator/), names overMaxName, full paths reachingMaxPath. Fall back to the full resolve for those.perflabel needs theaps5-summary.jsonllines ofmainand of the change from the same title, scene and machine plus thetools/trace_digest.pyoutput. If the start-up phase falls outside the frame summary, attach the title's own timing for both builds, the same way for each, in the PR.Please also sync with current
main(libkernel/CMakeLists.txtchanged) and rerun the focused APR tests.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T07:22:05Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
The author addressed the previously reported case-folding and fallback issues in the code, and the hosted checks pass on the current PR head. The remaining report and validation are still tied to the branch’s older base; current
mainhas since changedApr.cpp, and the repository still marks this PRneeds rebaseandperf numbers missing.What I ran
e8ba6924a4170e923d93acfc945c13f3c63314f9with current upstreammainedf6804cf52c62eacafc592dd6142cb4efe5bd05.git merge-tree --write-tree,git diff --check, andpython3 tools/check_conventions.py --base upstream/main.build-reviewtree has no APR test target.Results
git diff --checkUnedited local check output
Current
mainalso changescore/libs/prx/libkernel/Apr/src/Apr.cpp(the AMM pool implementation), which is the main production file changed by this PR. The merge preview is clean, but the old-base test result does not cover the integrated code.Negative control
The author reports that the PR’s focused suite passes on its tested tree. I did not independently run a negative control in this re-check.
Findings
Blocking
main, then rerun the focused APR suite on the integrated head, including a Linux run that exercises case-sensitive names. The reported 45/45 result is frommainf759e165d9, and currentmainchanged the same production file since then.perf numbers missing. The startup timing table is useful, but it does not provide the twoaps5-summary.jsonllines, attached traces andtrace_digest.pyresults required by the current performance-report rule. Since this measurement ends before the first frame, please get a maintainer decision on an acceptable startup-report format and record it before treating the perf requirement as satisfied.Non-blocking
Sources
e8ba6924a4170e923d93acfc945c13f3c63314f9mainedf6804cf52c62eacafc592dd6142cb4efe5bd05Not verified
I did not independently reproduce the Windows startup timings or the author-reported focused test results.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T21:00:05Z.
Review: COMMENTED
Reviewed — comments
The fast path builds and the focused path/APR tests pass on Linux. With
main's production files the newguest_apr_read_resolvetest fails, and reading the code turned up no new correctness problem. I could not reproduce the Windows start-up gain, and theperfevidence question raised earlier is still open, so this is not an approval.What I ran
Head
e8ba6924a4170e923d93acfc945c13f3c63314f9merged intomain086c0686c8adff3ee648fdbe34e0b0b647e1d511(--no-ff). Clean worktree, Debian 13 VM, GCC 14.2.0, Release, Ninja,BUILD_TESTING=ON.Results
git diff --checkcheck_conventions.pymaintoo and are unrelated (AGC denormal, network)savedata_replace_file_failure_tests. The selected build had skipped that executable, so the first run reported it "Not Run".guest_apr_read_resolvegit status --porcelainemptyNegative control
I restored
core/libs/prx/libc/include/General.hpp,core/libs/prx/libc/src/General.cppandcore/libs/prx/libkernel/Apr/src/Apr.cppfrommain, kept the PR's test, and rebuilt.guest_apr_read_resolvethen fails:APR mixed up two names that differ only in case. Onmainthe listing stores one size forE.binande.binon ext4, so the test does catch the ambiguity handling (Apr.cpp:78). The other sixguest_apr_read_*cases pass either way.With the merged files restored and rebuilt, the focused set passes 44/44 again.
Findings
Blocking
None from this review. MarcZX10's open point about the
perfevidence still stands. The phase ends before the first frame, soaps5-summary.jsonllines cannot show it, and the PR keeps theperf numbers missinglabel until a maintainer accepts the title's own start-up timing or names another format. I have nothing to add to that.Non-blocking
core/libs/tests/GuestAprRead.cpp:146). I confirm thuanquang's point by reading the code; I did not run it with the length guard removed. No file of that name is created, so the full resolve rejects it onmainand with the PR alike. Removing theMAX_NAME_LENGTHguard in_listedPath(Apr.cpp:148-160) would go unnoticed. Their suggestion would make the check bite on Windows: create a file of 128 ×é(256 UTF-8 bytes) and require that resolving it fails.What I checked by reading the merged tree, with no problem found:
hostDirectory / guestName(Apr.cpp:184) gives the same string asResolveHostPath'sChild(root, ...)for the direct hit, so a path resolved through the fast path and through the fallback maps to one id.SandboxCertificates.cpp, file-levelAddPathProvider). They are equivalent:ProvidedPathreturns the on-disk file when it exists, and when it does not, the file is absent from the listing and the fallback runs.BlockPathAliasbumps the generation, and a blocked directory throws inside thetry, which falls back to the full resolve.ResolveAliastakes that mutex, and the insert atApr.cpp:179re-checks the generation, so a directory resolved across an alias change is not cached.listedName == guestNamecompares the native strings case-sensitively, so on NTFS a guest spelling in other case still takes the full resolve, as onmain.Not verified
FindFirstFileWlisting with thetryaround_addListed, the non-UTF-8 fallback, and theD:-style component are not compiled or run on this Linux machine.To get this to a good state
perf numbers missingrequirement with a maintainer: either accept the title's start-up timing table already in the description, or name the format they want.éfile on Windows).Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T07:25:05Z.
Review: APPROVED
Reviewed — looks good
The reviewed change is sound on the inspected paths; no verified defect blocks merging.
What I ran
Reviewed head
5c5b61fc844b49358dff28854c5ac87866a83663usingrepo_read.pyagainst the prepared bundle and pinned source. No commands or tests were run by me; the description reports Windows 11 tests and timings.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I read all five files marked included in the manifest:
core/libs/prx/libc/include/General.hpp,core/libs/prx/libc/src/General.cpp,core/libs/prx/libkernel/Apr/src/Apr.cpp,core/libs/prx/libkernel/CMakeLists.txt, andcore/libs/tests/GuestAprRead.cpp. The manifest contains no excluded changed files. I did not run tests or independently verify the reported Windows results, benchmark captures, or behavior on other platforms.To get this to a good state
Nothing is required.