mirror of
https://github.com/pyenv/pyenv.git
synced 2024-12-23 06:53:13 +00:00
d8559b9749
The performance issue must be caused by too many I/O requests to `conda.txt` from fgrep. This inline expansion should work to reduce # of read to the `conda.txt`. original performance: ``` % git rev-parse HEAD4f76be6a12
% time bash -c 'pyenv rehash' bash -c 'pyenv rehash' 0.05s user 0.02s system 76% cpu 0.089 total ``` previous commit: ==> 4x slower than original ``` % git rev-parse HEAD4469d51ef7
% time bash -c 'pyenv rehash' bash -c 'pyenv rehash' 0.06s user 0.03s system 25% cpu 0.358 total ``` with this workaround: ==> almost same as original ``` % git rev-parse HEAD 3ffe91bdbc69220eaecf6e2088229cc27366c3f3 % time bash -c 'pyenv rehash' bash -c 'pyenv rehash' 0.05s user 0.00s system 68% cpu 0.082 total ```
47 lines
1.2 KiB
Bash
47 lines
1.2 KiB
Bash
# Anaconda comes with binaries of system packages (e.g. `openssl`, `curl`).
|
|
# Creating shims for those binaries will prevent pyenv users to run those
|
|
# commands normally when not using Anaconda.
|
|
#
|
|
# This hooks is intended to skip creating shims for those executables.
|
|
|
|
conda_exists() {
|
|
shopt -s nullglob
|
|
local condas=($(echo "${PYENV_ROOT}/versions/"*"/bin/conda" "${PYENV_ROOT}/versions/"*"/envs/"*"/bin/conda"))
|
|
shopt -u nullglob
|
|
[ -n "${condas}" ]
|
|
}
|
|
|
|
shims=()
|
|
for shim in $(cat "${BASH_SOURCE%/*}/conda.txt"); do
|
|
if [ -n "${shim%%#*}" ]; then
|
|
shims[${#shims[*]}]="${shim})return 0;;"
|
|
fi
|
|
done
|
|
eval "conda_shim(){ case \"\$1\" in ${shims[@]} *)return 1;;esac;}"
|
|
|
|
# override `make_shims` to avoid conflict between pyenv-virtualenv's `envs.bash`
|
|
# https://github.com/yyuu/pyenv-virtualenv/blob/v20160716/etc/pyenv.d/rehash/envs.bash
|
|
make_shims() {
|
|
local file shim
|
|
for file do
|
|
shim="${file##*/}"
|
|
if ! conda_shim "${shim}" 1>&2; then
|
|
register_shim "$shim"
|
|
fi
|
|
done
|
|
}
|
|
|
|
deregister_conda_shims() {
|
|
local shim
|
|
local shims=()
|
|
for shim in ${registered_shims}; do
|
|
if ! conda_shim "${shim}" 1>&2; then
|
|
shims[${#shims[*]}]="${shim}"
|
|
fi
|
|
done
|
|
registered_shims=" ${shims[@]} "
|
|
}
|
|
|
|
if conda_exists; then
|
|
deregister_conda_shims
|
|
fi
|