Conversation
rb_check_realpath_internal falls back to realpath_rec, which stats every component of every path, and Ruby runs it over each loaded feature while canonicalizing $LOADED_FEATURES - around 14 stats per file at typical depths. Windows can do the same job with one CreateFileW + GetFinalPathNameByHandleW + CloseHandle. win32/win32.c: add rb_w32_realpath(). It takes absolute drive-letter paths only, leaving relative and UNC paths to the walker, converts both the input and the result in stack buffers with a heap fallback for long paths, strips the "\\?\" NT namespace prefix (but not "\\?\UNC\"), and normalizes backslashes to forward slashes so $LOADED_FEATURES dedupes against Ruby's canonical form. file.c: use it in rb_check_realpath_internal, falling through to the emulated walker whenever it returns NULL (relative path, missing file, access denied). Measured on this VM: stat calls during require "gtk3" drop from 2495 to 413 (-83%), the require itself about 33 ms faster; File.realpath 107 -> 74 us.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rb_check_realpath_internalfalls back torealpath_rec, which stats every component of every path. Ruby runs it over each loaded feature while canonicalizing$LOADED_FEATURES— about 14 stats per file at typical depths. Windows can do the same job with oneCreateFileW+GetFinalPathNameByHandleW+CloseHandle.win32/win32.cgainsrb_w32_realpath(). It handles absolute drive-letter paths only, leaving relative and UNC paths to the walker; converts input and result in stack buffers with a heap fallback for long paths; strips the\\?\NT namespace prefix but not\\?\UNC\; and normalizes backslashes to forward slashes so$LOADED_FEATURESdedupes against Ruby's canonical form (aC:\foo\bar.rbcanonical would not match aC:/foo/bar.rbadded earlier, and the file would load twice).file.ccalls it fromrb_check_realpath_internaland falls through to the emulated walker whenever it returns NULL — relative path, missing file, access denied.Measured on this VM: stat calls during
require "gtk3"drop 2495 → 413 (−83%), the require itself ~33 ms faster;File.realpath107 → 74 µs.tzinfoandsqlite3unchanged.Windows-only; every other platform takes the existing path. Not built or tested on Windows CI — measured in a local MSYS2/UCRT64 VM.