versions: fast path for --bare --skip-aliases (#3411)

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)
This commit is contained in:
Jake Lodwick 2026-03-03 23:02:44 -08:00 committed by GitHub
parent aa2e8b8260
commit 23bcdebe18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,6 +26,29 @@ for arg; do
esac esac
done done
# Fast path for --bare --skip-aliases: skip sort and full realpath resolution
if [[ -n "$bare" && -n "$skip_aliases" ]]; then
versions_dir="${PYENV_ROOT}/versions"
if [ -d "$versions_dir" ]; then
shopt -s dotglob nullglob
for path in "$versions_dir"/*/; do
path="${path%/}"
if [ -L "$path" ]; then
# Relative link = internal alias → skip; absolute = external → keep
[[ "$(readlink "$path")" == /* ]] || continue
fi
echo "${path##*/}"
if [[ -z "$skip_envs" ]]; then
for env_path in "${path}/envs/"*; do
[ -d "$env_path" ] && echo "${env_path#${versions_dir}/}"
done
fi
done
shopt -u dotglob nullglob
fi
exit 0
fi
versions_dir="${PYENV_ROOT}/versions" versions_dir="${PYENV_ROOT}/versions"
if ! enable -f "${BASH_SOURCE%/*}"/pyenv-realpath.dylib realpath 2>/dev/null; then if ! enable -f "${BASH_SOURCE%/*}"/pyenv-realpath.dylib realpath 2>/dev/null; then