pyenv / pyenv-virtualenv

a pyenv plugin to manage virtualenv (a.k.a. python-virtualenv)
MIT License
6.16k stars 399 forks source link

fish shell _pyenv_virtualenv_hook slow #338

Open ephes opened 4 years ago

ephes commented 4 years ago

Hi *,

thanks for this awesome project at first :).

I noticed that my fish shell got really slow when just pressing enter compared to bash and I figured out that the line "status --is-interactive; and source (pyenv virtualenv-init -|psub)" in my fish config caused this to happen. It looks like this line creates a function that listens to the fish_prompt event:

function _pyenv_virtualenv_hook --on-event fish_prompt
    set -l ret $status
  if [ -n "$VIRTUAL_ENV" ]
    pyenv activate --quiet; or pyenv deactivate --quiet; or true
  else
    pyenv activate --quiet; or true
  end
  return $ret
end

I'm not sure what this function does, but it seems to get executed every time the fish_prompt is shown, which causes indeed performance problems. Would it maybe be enough to just listen to "--on-variable PWD" which would cause it to be executed every time the working directory changes?

best, jochen

wolph commented 3 years ago

Not just on fish, it's very slow with zsh as well.

It takes 100ms for every line you type in your shell...

ian-h-chamberlain commented 1 year ago

Based on #45 and this issue, I modified my config.fish by adding "manual initialization" instead of calling virtualenv-init by default, like so:

pyenv virtualenv-init - fish >> ~/.config/fish/config.fish

Then replacing --on-event fish_prompt with --on-variable PWD --on-variable PYENV_VERSION.

This greatly improves my feedback loop between prompts for most cases, and at least I only have to pay the pyenv-virtualenv penalty when explicitly setting PYENV_VERSION or changing directories. Would it make sense to upstream these changes (perhaps along with a fish_postexec hook that looks for the pyenv shell etc. commands like mentioned in https://github.com/pyenv/pyenv-virtualenv/issues/45#issuecomment-54648104) ?