Pyenv-virtualenv: Slow shell performance after running pyenv virtualenv-init

Created on 20 Apr 2018  路  12Comments  路  Source: pyenv/pyenv-virtualenv

It looks like there is some issue on my system that is causing very poor runtime performance after running pyenv virtualenv-init. Related to #132

I think the issue is with pyenv verision-name. What steps can I take to debug this further?

Most helpful comment

Similar problem on Debian 9 with zsh. Removing eval "$(pyenv virtualenv-init -)" from ~/.zshrc fixes it.

All 12 comments

This issue is caused by a 100ms delay added to every script executed with $()command substitution in the code. The entry point of pyenv sh-activate has number of sub-commands that get executed with this call. The call trace I'm seeing is:

pyenv sh-activate
-> pyenv-sh-activate                +100ms
  -> pyenv-version-name             +100ms
    -> pyenv-version-file           +100ms
    -> pyenv-version-file-read      +100ms
    -> pyenv-hooks                  +100ms
-> pyenv-virtualenv-prefix          +100ms
  -> pyenv-version-name             +100ms
    -> pyenv-version-file           +100ms
    -> pyenv-version-file-read      +100ms
    -> pyenv-hooks                  +100ms

All these calls add up to 1s+ of latency.

My theory is this is related to a virus scanner or carbonblack.

More progress. I can reproduce outside of pyenv now. 馃槃
I wrote a shell script that creates and calls another script. If the script has a shebang line in it, then the execution is horrendous.

#!/bin/bash
SUB_SCRIPT=$(mktemp)
if [[ $1 == "--bash" ]]; then
  echo "#!/bin/bash" > $SUB_SCRIPT
fi
echo "exit" >> $SUB_SCRIPT
chmod +x $SUB_SCRIPT
for X in $(seq 100); do
  $($SUB_SCRIPT)
done
rm $SUB_SCRIPT
$ time ./test.sh
./test.sh  0.05s user 0.08s system 37% cpu 0.341 total

$ time ./test.sh --bash
./test.sh --bash  0.24s user 0.23s system 3% cpu 11.869 total

Even on my unaffected system, the performance is measurably worse when shebang line exists.

$ time ./test.sh
./test.sh  0.07s user 0.08s system 94% cpu 0.156 total

$ time ./test.sh --bash
./test.sh --bash  0.15s user 0.16s system 87% cpu 0.351 total

running into the same problem too, on Ubuntu 16.04.

@Honghe Does your laptop run CarbonBlack? That was the root cause of my performance issue.

@cmcginty no running CarbonBlack ;(

Came here looking for a solution too. Added this to my zsh config and saw terrible performance. On Ubuntu 18.04. Removing this eval "$(pyenv virtualenv-init -)" removes the slowness.

Experiencing this^ too.

Similar problem on Debian 9 with zsh. Removing eval "$(pyenv virtualenv-init -)" from ~/.zshrc fixes it.

any news ?

What does eval "$(pyenv virtualenv-init -)" actually do? I just commented it out and have still been able to use pyenv with virtualenv with no problems.

What does eval "$(pyenv virtualenv-init -)" actually do? I just commented it out and have still been able to use pyenv with virtualenv with no problems.

It can automatically activate virtualenvs when a .python-version file is present.

What does eval "$(pyenv virtualenv-init -)" actually do? I just commented it out and have still been able to use pyenv with virtualenv with no problems.

It can automatically activate virtualenvs when a .python-version file is present.

So it just removes the need to run source venv/bin/activate?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CMLL picture CMLL  路  6Comments

draeath picture draeath  路  4Comments

Insoleet picture Insoleet  路  3Comments

hubitor picture hubitor  路  9Comments

andymccurdy picture andymccurdy  路  9Comments