GENERALLY NERDY RAMBLINGS

Speeding Up New Bash Shells

I try to keep my .bashrc lean, with just-in-time functions defined in external files and a minimum of unnecessary initialization.

Admittedly this is the end result of decades of tweaking. For some time, though, I’d been thinking that each time I opened a new terminal window/tab that that was taking far longer - a few seconds is far too long for the impatient - than seemed necessary. Time to shave this yak again.

First I spent some time with shellcheck to clean things up on general principals. That insured I wasn’t missing something obvious.

Next I decided it was time to go to the next level. Web searches turned up Profiling slow bashrc. That took a little effort to get working on MacOS - a brew install coreutils to enable the nanosecond capable gdate fixed that. Armed with that I began profiling what was taking so long.

After just a few minutes the culprit turned up: virtualenvwrapper’s initialization. In particular it seems /usr/local/bin/python3 -m virtualenvwrapper.hook_loader ... was measured at taking a full second or more though the delay seemed longer.

A few internet searches identified that this issue with virtualenvwrapper has been identified by others and that one solution is to simply initialize using virtualenvwrapper_lazy.sh.

Ahh, nice speedy new interactive shells in under two seconds again.