pyenv / pyenv-virtualenv

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

pyenv-virtualenv is very slow on macOS Sequoia #490

Open kozlek opened 2 weeks ago

kozlek commented 2 weeks ago

Too many issues will kill our team's development velocity, drastically. Make sure you have checked all steps below.

Prerequisite

Description

I was using pyenv & pyenv-virtualenv on macOS 12.x Monterey for 2 years with great success. Yesterday, I updated to macOS 15.0 Sequoia (clean install). The shell was very slow with pyenv-virtualenv autoloading enabled. It takes around 1.2 seconds when hitting a blank line in the shell.

I downgraded to macOS 13.x Ventura (clean install again) and the shell was instant again.

I don't expect you to fix macOS, but I wanted to report my experience with Sequoia to see if others users have the same problem. Apart from pyenv-virtualenv, pyenv + jenv + rbenv were also a bit slower. The rest of the apps were working well. I suspect Apple to have changed something with the terminal / shell...

I'll stick to Ventura for sometimes, and I'll give a try to Sonoma to see.

kozlek commented 2 weeks ago

I did a macOS 14.7 Sonoma clean install on an external SSD and pyenv-virtualenv is behaving normally, without any delays.

At least on my platform, macOS Sequoia has a huge issue with some shell programs.

I recommend to postpone the Sequoia upgrade until this is fixed on macOS side.

aphedges commented 1 week ago

I encountered this same problem yesterday on my Intel Mac running macOS 14.7 (Sonoma) when I updated from Xcode 15.3 to Xcode 16. I presume that your fresh install of macOS 15 (Sequoia) had Xcode 16, and I'd be curious to see whether downgrading only Xcode without downgrading the OS would solve the problem. I'm also curious about whether this is a problem only on Intel Macs or if it's a problem on Apple Silicon as well.

I noticed a variety of pyenv and pyenv-virtualenv commands being much slower, and I was able to figure out that the command pyenv sh-activate --quiet command run in the shell hook was taking most of the time when I hit "Enter" on a blank line. I ran the following command to help test out the problem:

time env -i bash -cx 'export PYENV_DEBUG=1; command pyenv sh-activate --quiet'

With Xcode 16, the command takes over 10 s to execute, while with Xcode 15.3, the command takes ~0.3 s to execute.

I can help with debugging the problem because I can't delay upgrading Xcode indefinitely. However, I have no clue how to profile shell scripts. If anyone has tooling recommendations, I can hopefully figure out exactly where the regression is happening.

native-api commented 1 week ago

However, I have no clue how to profile shell scripts.

https://github.com/pyenv/pyenv-virtualenv/issues/259#issuecomment-1282754854:

Try localizing the issue by timing the code that runs at prompt with:

export PS4='+($(date "+%s.%N")) (${BASH_SOURCE:-}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -x
<reproduce the problem>
set +x

Also add the same date invocation to PS4 assignments throughout Pyenv and Pyenv-Virtualenv and set PYENV_DEBUG=1