mirror of
https://github.com/ruby/ruby.git
synced 2026-07-31 09:25:15 +08:00
`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 c091c186e4) +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 fcd210086c) +PRISM [aarch64-linux] built-ruby: ruby 4.1.0dev (2026-04-09T06:38:09Z get-cwd-cache 6774af9ba7) +PRISM [aarch64-linux] ``` | |compare-ruby|built-ruby| |:--------|-----------:|---------:| |Dir.pwd | 4.157M| 5.541M| | | -| 1.33x|
3 lines
26 B
YAML
3 lines
26 B
YAML
benchmark:
|
|
pwd: Dir.pwd
|