Skip to content

file_system: cut console-path parse allocations (7->1 on G:, 11->3 on T:, -84% parse CPU) - #8045

Open
TG0000 wants to merge 1 commit into
ItsNotRexed:mainfrom
TG0000:perf/runtime-latency-fast
Open

TG0000 wants to merge 1 commit into
ItsNotRexed:mainfrom
TG0000:perf/runtime-latency-fast

Conversation

@TG0000

@TG0000 TG0000 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Item: PERF-FS-PARSE (claimed in #7913)

What

runtime/shims/file_system.cpp parsed every console path (G: / T: / C:\) with several heap allocations and copies before the real filesystem call:

  • console_drive compared the GAME: prefix through a lowered substring.
  • For G:/T: paths, both roots were copied out of the lock and lies_under lowered copies of the path and of each root.
  • parse_console grew each component a character at a time and copied it into parts.
  • Every T: path ran std::filesystem::create_directories on the scratch folder, whose status opens a handle to it.

Now the prefix and roots are compared in place (roots under g_mutex), components are sliced from the path, and create_directories only runs when GetFileAttributesW does not report the folder. The parse result is unchanged; behaviour is meant to be identical.

Numbers (parse step only, -O2)

Path Before After Change Allocations
G: 1,466 ns 225–243 ns −84% 7 → 1
T: −30–32% 11 → 3
C:\ −68%

Whole GetFileAttributesW: only −5 to −12%, because the OS filesystem probes dominate. The win is real but small end to end; it is mostly CPU and allocator pressure on a call the game makes very often.

Tests

  • file_system_test: 446/446 passed.
  • New runtime/test/file_system_parse_test.cpp (wired into runtime/CMakeLists.txt): compares the new parse with the earlier code on edge cases, 272/272 passed, plus 200,000 generated paths with no differences.
  • Both built and run under llvm-mingw clang++ -O2.
  • Not run locally: the MSVC / CMake build. The CMake change is a small test target addition; CI is the first place it gets built that way.

Conflicts

Checked against #7672, #4965, #3962, #7099 and #5234: no overlapping hunks. Other open file_system pull requests were not compared line by line.

AI-assisted

This change was written with AI assistance (Claude) and reviewed and tested as above. No game data is used; the test builds its paths by hand.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

🤖 Generated with Claude Code

console_drive compared the GAME: prefix through a lowered substring, and for G:/T: paths copied both roots out of
the lock and lowered copies of the path and each root in lies_under; parse_console grew each component a character
at a time and copied it into parts; and every T: path ran std::filesystem::create_directories on the scratch folder,
whose status opens a handle to it. Now the prefix and roots are compared in place (roots under g_mutex), components
are sliced from the path, and create_directories only runs when GetFileAttributesW does not report the folder.

file_system_parse_test checks the parse against the earlier code on edge cases and 200 000 generated paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Xiiano Xiiano left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot IDE:
Task completed:

Reviewed PR #8045 against main. Found no high-confidence bugs or memory-safety, Vulkan/SPIR-V, or repository-convention violations in the actual branch diff. The optimized in-place parsing preserves component, root, separator, and colon handling; T scratch setup preserves the prior last-error value and correctly avoids repeated directory creation. The synthetic reference test and CMake/CTest wiring match the repository patterns. Local build/test execution was unavailable because no C++/CMake tools are installed in the accessible environment.

@ikurta92-png

Copy link
Copy Markdown

Tested 51ee52b7a natively on Windows (11 Pro 10.0.26300, MSVC 19.51, SDK 10.0.26100, CMake VS generator, RelWithDebInfo, i5-12400): pass, both tests green 3/3 under MSVC/CMake

  • file_system_parse_test (ctest file_system_parse): 272 check(s), 0 failure(s) in 3/3 runs, about 0.55 s each. No mismatch lines, so the edge cases and the 200 000 generated paths match the embedded reference parser. The scratch-folder checks pass too, and %TEMP%\leonida_file_system_parse_test is removed afterwards.
  • file_system_test (ctest file_system): 446 check(s), 0 failure(s) in 3/3 runs, the same as main (446 / 0).
  • The new CMake target and add_test configure and build cleanly with the Visual Studio generator.
  • MSVC /W4 warnings in changed files: one, file_system_parse_test.cpp(193,22): warning C4996: '_wfopen': This function or variable may be unsafe. None in file_system.cpp.
  • Not covered: the allocation counts and CPU savings claimed in the title (not measured), a run with the game.

AI-assisted (Claude Code). Synthetic test only, no game files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants