perf(libc): avoid repeated Windows path component scans #7467
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7467"
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 Dripl1x on 2026-10-18T08:47:05Z.
What
Avoid repeated case-insensitive directory scans while resolving Windows guest paths. Use
FindFirstFileExWonly when the directory explicitly reports case-insensitive behaviour, return existing non-reparse paths directly, and start component matching at the longest existing ancestor. Preserve enumeration for case-sensitive directories and failed or unsupported attribute queries.Tested
Rebased onto main
e1dae23e01a412571c2575fe794475b4c0e7adf9; source head5a1590c9f8eefc50d7080f26fae3b8ed07ff99bc. Merge compatibility was also checked against later main5057673804b28d217559010d7ac1f702824f240b. Thanks to @blawesom for porting the prefix walk to main's split-nameResolveHostPathinterface and reporting Linux coverage.The port initially advanced
firsttolastafter selecting the existing parent, skipping the final component. The Windowsguest_filesystemtest reproduced the failure at parent traversal before the fix. Changing the iterator tostd::prev(last)preserves the final component; rebuilding and rerunning the same test passes. The regression coverage for mixed-case file/directory lookup, relinked module names and ambiguousBoth/bothnames on NTFS case-sensitive directories is retained and passes. The libc runtime was rebuilt from the corrected source. @blawesom's Linux results in the review are credited as their validation, not a fresh local full-suite run.SuperTuxKart captures for the bot's before/after requirement: Windows 11 Pro build 26300, Ryzen 7 5800H, RTX 3070 Laptop GPU, NVIDIA 617.42, WinLibs GCC 15.2.0 r7, Release; SuperTuxKart (PPSA69421) tutorial prompt over the main menu, 1920x1080 internal rendering in a maximized 2560x1369 window, warm shader caches, audio muted, no input;
APS5_TRACE_SECONDS=20:8withAPS5_TRACE_EVENTS=1048576, console output not redirected, no profiling switches; 2026-10-21, A-B-B-A, order main, PR, PR, main.rv21-t01-main-e1e1dae23e01a4e1dae23e01a4rv21-t04-main-e1e1dae23e01a4e1dae23e01a4rv21-t02-74675a1590c9f8eerv21-t03-74675a1590c9f8eeThe FPS difference is within the run-to-run spread of main; this PR claims no FPS change. What it saves is shown under Where it helps.
Summary lines (main first, then this PR)
tools/performance_compare.py(first capture of each side)Performance comparison
e1dae23e015a1590c9f8Configuration differences
Frame and GPU times (ms)
Top phases (ms per frame)
tools/trace_digest.pyoutput (first capture of each side; all digests are in the evidence archive)rv21-t01-main-e1seconds 20:8 from present 37: 76 presents, frame p50 105.7 / p90 107.9 / p99 110.8 / max 110.8 ms, GPU busy 5.4 ms per present
NVIDIA GeForce RTX 3070 Laptop GPU, NVIDIA 617.42, Windows 10.0.26300, 1920x1080, commit
e1dae23e01, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
rv21-t02-7467seconds 20:8 from present 67: 76 presents, frame p50 104.7 / p90 108.0 / p99 123.2 / max 123.2 ms, GPU busy 5.4 ms per present
NVIDIA GeForce RTX 3070 Laptop GPU, NVIDIA 617.42, Windows 10.0.26300, 1920x1080, commit
5a1590c9f8, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
The earlier seven filesystem cases and UI Lab/homebrew navigation evidence predate this rebase. No startup-duration improvement is claimed. vkQuake's known baseline flicker/black-floor issue remains outside this change.
Where it helps
Path resolution happens mostly while the title starts and loads. Over the whole run the call counts are identical on both sides, so totals compare directly (CPU time summed over the calling threads, not wall-clock startup time):
ResolveHostPathMatchNamesCounters come from a local probe build that is not part of this PR (
review-probe.patchin the evidence archive): the same counters and timers were inserted into main2185dbf92eand into main with all eleven series PRs merged (#7464 in its rebased form), anchored on function definitions present in both trees. Runs were in the mirrored order main, series with #7464 reduced to its wake only, series, series, reduced series, main, in the scene above withAPS5_PROFILE_DRAW=1; values are medians of two runs over the same 8-second window as the trace, starting 20 s after the first flip, per flip. These runs carry profiling overhead and are not used for FPS. Each optimised function below is changed by this PR only; counters show where the work goes, not an isolated FPS gain.Dependencies and overlap
No required PR dependency. Main's current vector-based path interface is preserved. The earlier review correction for case-sensitive directories remains in place; #6061 and #6226 were previously identified as related path-resolution overlaps and are not claimed as this implementation.
Re-checked on 2026-10-21: this head still merges cleanly into main
2185dbf92e. #6658, which the earlier combined runs carried, merged into main on 2026-10-20.Checklist
Reproduction evidence
Windows negative-control/fixed test logs, source provenance, frozen runtime manifests and completed/incomplete game-run records. Earlier series evidence is historical and tied to its original revisions. Current hosted checks are shown in the PR checks; no full-suite result is inferred from metadata checks.
Update of 2026-10-21: 7467-evidence.zip (traces, summary lines,
trace_digest.pyandperformance_compare.pyoutput, loaded-module hashes), counters where.json and the probe review-probe.patch with probe_window.py.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T08:58:22Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libc/src/General.cppL88-89Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libc/src/General.cppcore/libs/tests/GuestFilesystem.cppcore/libs/prx/libc/src/General.cppcore/libs/prx/libc/src/General.cppcore/libs/prx/libc/src/General.cppcore/libs/tests/GuestFilesystem.cppcore/libs/tests/GuestFilesystem.cppcore/libs/prx/libc/src/General.cppImported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-18T12:32:15Z.
I ran a differential test of the old and new
MatchNames/ResolveHostPathbodies, compiled together into one harness (Windows 11 26300, Ryzen 5 9600X, WinLibs GCC 15.2.0, Release, PR merged ontomain9f25d0bf5). It ran 40,000 random paths over a tree containing a normal directory, a junction, a dangling symlink,..,.and trailing slashes. The results are identical except inside a directory with the per-directory case-sensitive attribute (fsutil file setCaseSensitiveInfo <dir> enable). There, 759 of the 40,000 results differ.In this example, directory
SenscontainsFile.txt,Sub/, and bothBothandboth:mainSens/file.txtSens/File.txtSens/file.txt(does not exist)Sens/subSens/SubSens/sub(does not exist)sens/BOTH/FILE.TXTsens/BOTH/FILE.TXT(does not exist)The cause: inside a case-sensitive directory,
FindFirstFileExW(dir\file.txt)returnsERROR_FILE_NOT_FOUNDeven withoutFIND_FIRST_EX_CASE_SENSITIVE. The olddirectory_iterator+SameNamescan findsFile.txt. On NTFS this is the main case where the fallback matters at all, sinceGetFileAttributesWalready matches case-insensitively in ordinary directories.Either of these would keep the old behaviour:
FILE_CASE_SENSITIVE_INFORMATIONviaGetFileInformationByHandleEx);The speedup is real for misses: a missing name in a 3,000-entry directory takes 14.8–17.3 ms on
mainand 0.26 ms with this PR. Existing paths are unchanged at about 30–50 µs. The 462-test set (guest_,libkernel,libcand related) passes onmainand with this PR.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-18T13:14:35Z.
@wachi35676 Thanks for the differential test and the case-sensitive directory reproducer. Fixed in
feed2ea53c00: the pattern lookup is now used only when the directory explicitly reports case-insensitive behaviour; case-sensitive directories and failed/unsupported attribute queries use the original enumeration. The new guest filesystem regression covers mixed-case file/directory lookup, relinked module names and ambiguous Both/both names on an NTFS case-sensitive directory. It fails with the previous implementation and passes with the correction.The three corrections (#7467, #7469 and #7470) were also checked together against the previous series in a same-scene SuperTuxKart A-B-B-A repeat: 32.680 -> 32.722 FPS (1920x1080 internal rendering, maximized 2560x1369 client, warm caches, trace seconds 20-28, RTX 3070 Laptop/NVIDIA 617.42). Focus and loaded-module hashes were verified. This combined check does not assign a separate FPS gain to this PR. #7473 is being validated separately.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-18T16:36:08Z.
Rebase handoff, with a port onto
main's reworked signature —mainchangedResolveHostPathto take split name vectors withChild()/JoinNames()helpers while this PR's scan-avoidance was written against thestd::filesystem::pathform. The merged version keepsmain's structure and ports your Windows prefix walk onto it: the reparse-point scan walks the vector prefixes (longest existing non-reparse parent first) and advances thefirstiterator into the vector, so the component loop starts where the scans left off — the same single-scan behaviour, onmain's shape. Worth a review of that hunk since it is a port, not a transcription.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; the path/filesystem tests pass; full suite green apart from the two knownmainregressions (agc_driver_tessellation— Mesa, #5444;agc_driver_bda_device— #7584), neither from this PR (your Windows prefix walk is_WIN32-gated).To pick it up:
Head is
4703ca7e0.Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-18T18:28:48Z.
Thanks for porting this to main's split-name interface and for the Linux validation. Picked up the handoff and rebased onto main
e1dae23e01. Windows validation caught one iterator error in the port: after selecting the existing parent, first = last skipped the final path component. Changed it to first = std::prev(last). The existing guest_filesystem parent-traversal case fails before this correction and passes after rebuilding with it; the earlier case-sensitive NTFS and relinked-module regression coverage is retained. Published head:5a1590c9f8. The PR description distinguishes the completed filesystem checks from the incomplete game repeat. Negative-control and fixed-run logs, source provenance and runtime manifests: https://github.com/Dripl1x/AnyPS5/releases/download/performance-series-20261018/review-rebase-20261018.zipImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T21:44:38Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-18T23:40:34Z.
Re-checked
5a1590c9fmerged ontomain07377573f(Windows 11 26300, GCC 15.2).Differential test: I compiled the old and new
ResolveHostPathbodies into one harness. They give 0 differences over 40,006 paths, on a tree with a case-sensitive directory, a junction, a dangling symlink, trailing slashes and module relinking. Spot checks:Sens/file.txt→Sens/File.txtsens/deep/in/LEAF.bin→sens/Deep/In/Leaf.binSens/BOTHstill raises the ambiguity error.The only remaining differences need a
..component, whichResolve()removes before callingResolveHostPath.Prefix walk: the
std::prev(last)walk handles empty, single-component, none-existing, all-existing and reparse-in-the-middle paths exactly asmaindoes.New test:
TestCaseSensitiveHostDirectorypasses. WithMatchNamesforced back to theFindFirstFileExWlookup, it fails with0xc0000409.Speed: a miss in a 3,000-entry directory still goes from about 31 ms to about 0.3 ms. Case-sensitive directories keep
main's cost.Regression set: the 472-test set passes.
guest_selectandguest_select_waitflaked under-j4and pass when run serially.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-20T23:34:16Z.
Updated the description: before/after summary lines from the same machine and SuperTuxKart scene (main
e1dae23e01a49.46 / 9.31 FPS, this PR5a1590c9f8ee9.45 / 9.40 FPS, so no FPS claim),trace_digest.pyandperformance_compare.pyoutput, and probe counters that show where this change saves work in that scene: at identical call counts over the run (11,928ResolveHostPath, 7,460MatchNames, mostly while the title starts), path resolution takes 9.25 s on main and 5.46 s with this PR, andMatchNames4.72 s against 1.93 s (CPU time summed over threads, not wall-clock startup). Traces, digests and the probe patch are in the evidence release. The head is unchanged and still merges cleanly into current main.AI-assisted: yes (Claude Code)