Skip to content

[pull] master from ruby:master#923

Merged
pull[bot] merged 2 commits intoturkdevops:masterfrom
ruby:master
Apr 10, 2026
Merged

[pull] master from ruby:master#923
pull[bot] merged 2 commits intoturkdevops:masterfrom
ruby:master

Conversation

@pull
Copy link
Copy Markdown

@pull pull bot commented Apr 10, 2026

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 : )

byroot added 2 commits April 10, 2026 09:56
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|
@pull pull bot locked and limited conversation to collaborators Apr 10, 2026
@pull pull bot added the ⤵️ pull label Apr 10, 2026
@pull pull bot merged commit cfec60d into turkdevops:master Apr 10, 2026
0 of 2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant