perf(libkernel): resolve an APR path's directory once and find the file in its listing #10633
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10633"
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-24T13:44:58Z.
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; a path whose file is not in the listing (created since, or an unusual name), a relative path and a path ending in.,..or a separator take the full resolve as before.Measured
Demon's Souls PPSA01342 v1.005 resolves its whole package at start-up (
ResourcePool::GatherResourceFileInfo, about 243,000 entries in 10,059 directories), Windows 11, Samsung 980 NVMe:GetFileAttributesWon each of the 223,311 files: 37.4 s (167 us each); listing all 10,059 directories: 2.1 s.ResourcePool::GatherResourceFileInfo() took49.07 s on main, 6.5 to 9.3 s with this change.Tests
New case
guest_apr_read_resolve: absolute paths in one directory and a subdirectory, a name in other case, the same id for a path resolved again, a file created after its directory was listed, and a missing file (error_index, size 0).guest_apr_read_*andguest_ampr*pass on Windows (WinLibs GCC 15.2.0).🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T13:46:41Z.
Review: CHANGES_REQUESTED
The new guest-to-host directory cache can keep resolving a reused mount point to its old host directory.
g_hostDirectoriesis keyed only by the guest directory string and has no invalidation when aliases change. For example: resolve an APR file under/savedata0while it is mounted to save A; unmount it (sceSaveDataUmount2callsRemovePathAlias_nid_no_patch); mount save B into the now-free slot (mount3callsAddPathAlias_nid_no_patchwith the same/savedata0prefix); then resolve the same guest directory again._listedPathhits the cached path for save A and may return A's file/size or fail to find B's file, despite the current alias pointing to B. SaveData slots are explicitly reused, and AddPathAlias replaces a same-prefix mapping.Please invalidate or version this cache when aliases change, or avoid caching across mutable alias mappings. A focused regression can resolve an APR path in one alias target, rebind that prefix to a second directory with a different file, then verify a second resolution/read uses the second target. I have not run this regression locally; this finding is from tracing the exact cache and alias lifecycle in the current source.
Pull request closed