1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-12-22 17:28:01 +00:00

Improve startup time by skipping pyenv rehash

After profiling startup time, I found that "pyenv rehash" is
by far the slowest piece. This change skips rehashing on init.

See https://github.com/pyenv/pyenv/issues/784#issuecomment-404850327

Also pass the shell explicitly, as suggested in
https://github.com/pyenv/pyenv/issues/784#issuecomment-404944318,
which provides a modest improvement.

In total, this improves startup time from 1s to 0.3s on my machine.
Using the following command:
python -m timeit "__import__('subprocess').Popen(['zsh', '-i', '-c', 'echo']).communicate()"

Result before this change:
10 loops, best of 3: 1 sec per loop

Result after this change:
10 loops, best of 3: 334 msec per loop
This commit is contained in:
Steven Loria 2018-07-14 09:40:39 -04:00 committed by Indrajit Raychaudhuri
parent e064d5c65f
commit dacef14214

View File

@ -11,12 +11,12 @@
if [[ -s "$HOME/.pyenv/bin/pyenv" ]]; then if [[ -s "$HOME/.pyenv/bin/pyenv" ]]; then
path=("$HOME/.pyenv/bin" $path) path=("$HOME/.pyenv/bin" $path)
export PYENV_ROOT=$(pyenv root) export PYENV_ROOT=$(pyenv root)
eval "$(pyenv init -)" eval "$(pyenv init - --no-rehash zsh)"
# Load package manager installed pyenv into the shell session. # Load package manager installed pyenv into the shell session.
elif (( $+commands[pyenv] )); then elif (( $+commands[pyenv] )); then
export PYENV_ROOT=$(pyenv root) export PYENV_ROOT=$(pyenv root)
eval "$(pyenv init -)" eval "$(pyenv init - --no-rehash zsh)"
# Prepend PEP 370 per user site packages directory, which defaults to # Prepend PEP 370 per user site packages directory, which defaults to
# ~/Library/Python on macOS and ~/.local elsewhere, to PATH. The # ~/Library/Python on macOS and ~/.local elsewhere, to PATH. The
@ -106,7 +106,7 @@ if (( $+VIRTUALENVWRAPPER_VIRTUALENV || $+commands[virtualenv] )) && \
if (( $pyenv_plugins[(i)virtualenv-init] <= $#pyenv_plugins )); then if (( $pyenv_plugins[(i)virtualenv-init] <= $#pyenv_plugins )); then
# Enable 'virtualenv' with 'pyenv'. # Enable 'virtualenv' with 'pyenv'.
eval "$(pyenv virtualenv-init -)" eval "$(pyenv virtualenv-init - zsh)"
# Optionally activate 'virtualenvwrapper' plugin when available. # Optionally activate 'virtualenvwrapper' plugin when available.
if (( $pyenv_plugins[(i)virtualenvwrapper(_lazy|)] <= $#pyenv_plugins )); then if (( $pyenv_plugins[(i)virtualenvwrapper(_lazy|)] <= $#pyenv_plugins )); then