Skip to content

perf(zsh): resolve brew --prefix at template time and cache completions#13

Merged
chagui merged 1 commit into
mainfrom
chagui/zsh/startup-perf
Apr 25, 2026
Merged

perf(zsh): resolve brew --prefix at template time and cache completions#13
chagui merged 1 commit into
mainfrom
chagui/zsh/startup-perf

Conversation

@chagui
Copy link
Copy Markdown
Owner

@chagui chagui commented Apr 9, 2026

Zsh startup was measured at ~5.6s. The dominant costs were op completion zsh (4-11s, already cached in a prior commit), 11 runtime brew --prefix subshell calls (~450ms total), gt completion (~390ms), and zoxide init (~25ms).

All brew --prefix calls are now resolved at chezmoi apply time using the output template function. The rendered config contains literal /opt/homebrew paths instead of forking Ruby on every shell init. The llvm check was also corrected from -n (always true since brew --prefix returns a path regardless of install state) to -d (checks the directory actually exists).

Graphite and zoxide initialization output is cached to $XDG_CACHE_HOME/zsh/ on first use and sourced from disk on subsequent inits. Run rm ~/.cache/zsh/*.zsh to force regeneration after tool upgrades.

A duplicate asdf sourcing was removed — it was loaded in both the zshrc darwin block and tools.zsh, resulting in three unnecessary brew --prefix asdf calls. The tools.zsh copy is kept since it also sets the required env vars.

All which calls replaced with command -v (shell builtin, avoids forking an external process).

Expected startup improvement from ~5.6s to under 0.5s.

🤖 Generated with Claude Code

@chagui chagui force-pushed the chagui/zsh/startup-perf branch from 3468423 to c6599f4 Compare April 9, 2026 10:47
@chagui chagui force-pushed the chagui/zsh/startup-perf branch from c6599f4 to 553603b Compare April 25, 2026 09:18
Zsh startup was ~5.6s due to 11 runtime `brew --prefix` subshell calls
(~450ms), `gt completion` (~390ms), and `op completion zsh` (4-11s).

- Resolve all `brew --prefix` calls at `chezmoi apply` time using
  the `output` template function instead of runtime `$()` subshells
- Cache `gt completion` and `zoxide init` output to
  $XDG_CACHE_HOME/zsh/ (generated once, sourced thereafter)
- Remove duplicate asdf sourcing (was in both zshrc and tools.zsh)
- Replace `which` with `command -v` (shell builtin, no fork)

To invalidate completion caches: rm ~/.cache/zsh/*.zsh

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@chagui chagui force-pushed the chagui/zsh/startup-perf branch from 553603b to 4899dcf Compare April 25, 2026 19:22
@chagui chagui merged commit 7b9ed9c into main Apr 25, 2026
1 check passed
@chagui chagui deleted the chagui/zsh/startup-perf branch April 25, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant