[pull] master from ruby:master#923
Merged
pull[bot] merged 2 commits intoturkdevops:masterfrom Apr 10, 2026
Merged
Conversation
This extra check is a hotspot for path operations on macOS. It was added in 9962aad because of a limitation of HFS+. But all the invalid characters are outside of ASCII range, and most paths are ASCII, so we can optimistically check the coderange instead. Most `rb_str_normalize_ospath` were first checking for ASCII range, but a few like `rb_dir_getwd_ospath` in `dir.c` or `ospath_new` in `file.c` didn't.
`rb_dir_getwd_ospath()` is called quite frequently, but the overwhelming majority of the time, the current directory didn't change. We can also assume that most of the time, `PATH_MAX` is enough for `getcwd`, hence we can first attempt to use a small stack buffer rather than always allocate on the heap. This way we can keep the last `pwd` and revalidate it with no allocation. On macOS syscalls are fairly slow, so the gain isn't very large. macOS: ``` compare-ruby: ruby 4.1.0dev (2026-04-09T05:19:02Z master c091c18) +PRISM [arm64-darwin25] built-ruby: ruby 4.1.0dev (2026-04-09T06:37:20Z get-cwd-cache ea02126d79) +PRISM [arm64-darwin25] ``` | |compare-ruby|built-ruby| |:--------|-----------:|---------:| |Dir.pwd | 105.183k| 113.420k| | | -| 1.08x| ``` Linux (inside virtualized Docker) ``` compare-ruby: ruby 4.1.0dev (2026-04-07T08:26:25Z master fcd2100) +PRISM [aarch64-linux] built-ruby: ruby 4.1.0dev (2026-04-09T06:38:09Z get-cwd-cache 6774af9) +PRISM [aarch64-linux] ``` | |compare-ruby|built-ruby| |:--------|-----------:|---------:| |Dir.pwd | 4.157M| 5.541M| | | -| 1.33x|
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )