# Zsh Startup Performance Rules
## Rule
Zsh interactive shell startup MUST complete in under 200ms. Heavy tools (nvm, pyenv, conda, kubectl completions) MUST be lazy-loaded.
## Performance Budget
| Component | Max Time |
|-----------|----------|
| Total startup | < 200ms |
| compinit | < 30ms |
| Oh My Zsh plugins (combined) | < 100ms |
| Single plugin | < 20ms |
| Prompt init | < 20ms |
## Measurement
```bash
# Measure total startup time
time zsh -i -c exit
# Profile with zprof
# Add to TOP of .zshrc:
zmodload zsh/zprof
# Add to BOTTOM of .zshrc:
zprof
```
## Lazy-Loading Pattern
```bash
# Good: nvm loaded on first use (saves ~500ms)
lazy_load_nvm() {
unset -f nvm node npm npx
export NVM_DIR="$HOME/.nvm"
[[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh"
}
nvm() { lazy_load_nvm; nvm "$@"; }
node() { lazy_load_nvm; node "$@"; }
npm() { lazy_load_nvm; npm "$@"; }
npx() { lazy_load_nvm; npx "$@"; }
# Bad: loaded eagerly (adds 500ms+)
export NVM_DIR="$HOME/.nvm"
source "$NVM_DIR/nvm.sh"
```
## Plugin Limits
```bash
# Good: 5-8 essential plugins
plugins=(git z fzf zsh-autosuggestions zsh-syntax-highlighting)
# Bad: 15+ plugins
plugins=(git docker kubectl aws npm yarn python ruby rails
z fzf zsh-autosuggestions zsh-syntax-highlighting
colored-man-pages web-search encode64)
```
## Compinit Caching
```bash
# Good: rebuild once per day
autoload -Uz compinit
if [[ -n ~/.zcompdump(#qN.mh+24) ]]; then
compinit
else
compinit -C
fi
# Bad: rebuild every startup
autoload -Uz compinit && compinit
```
## Good
```bash
# Profile output shows < 200ms total
# num calls time self name
# 1) 1 15.20 45.00% 15.20 45.00% compinit
# 2) 1 8.30 24.56% 8.30 24.56% _zsh_highlight
```
## Bad
```bash
# Profile output shows > 500ms
# num calls time self name
# 1) 1 520.00 65.00% 520.00 65.00% nvm_auto
# 2) 1 180.00 22.50% 180.00 22.50% compinit
```