heroku autocomplete script doubles zsh login times
Do you want to request a feature or report a bug?
BUG
What is the current behavior?
The default heroku autocomplete script adds significant load time to a ZSH login, as observed in MacOS terminal.app.
The default heroku autocomplete script adds autocompletion commands for ZSH. It advises the user to run printf "$(heroku autocomplete:script zsh)" >> ~/.zshrc; source ~/.zshrc, which in turn adds the following to the end of .zshrc
# heroku autocomplete setup
HEROKU_AC_ZSH_SETUP_PATH=/Users/$USERNAME/Library/Caches/heroku/autocomplete/zsh_setup && test -f $HEROKU_AC_ZSH_SETUP_PATH && source $HEROKU_AC_ZSH_SETUP_PATH;
The zsh_setup script loads compinit at the bottom:
autoload -Uz compinit;
compinit;
However, my current .zshrc already has the following command near the top of the script, used for other autocomplete programs:
autoload -Uz compinit && compinit
Having this run twice, before and after changes to fpath, adds significant load time. To demonstrate the slowdown, here is the output of zprof with Heroku default setup of loading the script at the bottom of .zshrc, showing extended process times for compdump and compinit.
num calls time self name
-----------------------------------------------------------------------------------
1) 2 303.24 151.62 37.84% 303.24 151.62 37.84% compdump
2) 2 799.04 399.52 99.71% 288.59 144.30 36.01% compinit
3) 1532 163.09 0.11 20.35% 163.09 0.11 20.35% compdef
4) 4 44.19 11.05 5.51% 44.19 11.05 5.51% compaudit
What is the expected behavior?
Tested on MacOS 11.0.1, but also observed in MacOS 10.15.7, I expect the script to be compatible with existing and common .zshrc configurations. The addition of Heroku autocomplete should not significantly slowdown zsh login.
Temporary Workaround
To temporarily remediate the unexpected behavior, I moved the Heroku Autocomplete script to the top of my .zshrc, before my own autoload -Uz compinit && compinit command and others. The speed increase is significant.
num calls time self name
-----------------------------------------------------------------------------------
1) 4 41.13 10.28 48.77% 41.13 10.28 48.77% compaudit
2) 2 81.43 40.72 96.55% 40.30 20.15 47.78% compinit
...
9) 1 0.08 0.08 0.10% 0.08 0.08 0.10% compdef