Commit 8037f226 introduced the `--executables` fast path using
`xargs -r` and `basename -a`. Those options are unavailable on
illumos and OpenBSD, breaking `pyenv rehash` on those platforms.
Replace the GNU-specific invocation with a Bash 3.2-compatible
implementation while preserving the direct executable discovery
optimization.
Replace the use of `xargs -r` and `basename -a` in the
`--executables` fast path with Bash 3.2-compatible parameter
expansion.
The previous implementation relied on non-portable utility options,
causing `pyenv rehash` and shell initialization to fail on illumos,
OpenBSD, and other non-GNU userlands.
Preserve the optimized executable discovery path by continuing to
discover executables directly from the versions directory and
deduplicate their basenames.
Skip sort, native extension probe, and per-symlink realpath
when called with --bare --skip-aliases (the rehash case).
Use readlink to distinguish internal aliases (relative target)
from external installs (absolute target).
In MacOS, speeds up rehash by 5.2 ms (7%) in empty environment,
55.9 ms (33%) in a regular environment (3 ver, 12 venvs, 320 bins),
93.7 ms (15%) in a large environment (6 ver, 60 venvs, 1466 bins)
* Remove all use of `greadlink`, fix#2654
Signed-off-by: Harry Chen <i@harrychen.xyz>
* revert greadlink back in tests
---------
Signed-off-by: Harry Chen <i@harrychen.xyz>
Co-authored-by: Anton Petrov <anton.a.petrov@gmail.com>
"hyperfine pyenv-versions" before with my bash 4.4:
Time (mean ± σ): 81.7 ms ± 2.2 ms [User: 67.8 ms, System: 15.7 ms]
Range (min … max): 78.3 ms … 87.2 ms 34 runs
After:
Time (mean ± σ): 70.6 ms ± 2.4 ms [User: 55.6 ms, System: 16.9 ms]
Range (min … max): 67.9 ms … 78.9 ms 41 runs
All scripts in libexec/ (excluding pyenv) are called through pyenv,
therefore the shebang lines are not necessary. On some systems this
provides a measurable increase in performance of the shell prompt.
Related to pyenv/pyenv-virtualenv#259