> The article says something about zsh “caching” a static sourced file; does it actually do something like that? It still has to run the shell code, right?
No it does not, the article is wrong or phrased incorrectly.
Zsh completion functions, when properly configured, are autoloaded. The function is only read from disk when called. Say with _kubectl, if you do it correctly with a static _kubectl instead of following the stupid advice of `source <(kubectl completion zsh)`, on shell startup your _kubectl should be uninitialized:
$ which _kubectl
_kubectl () {
# undefined
builtin autoload -XUz
}
After you actually try to complete kubectl once, run that again and this time you can see the actual function body.
$ which _kubectl
_kubectl () {
local shellCompDirectiveError=1
# ...
}
That function is read from disk on use, not cached.
What zsh does cache, with compinit[1], is association of commands with completion functions. compinit reads the #compdef line of functions on $fpath (e.g. `#compdef _kubectl kubectl`), and generates a ~/.zcompdump (or some other path, mine is ~/.local/share/zsh/compdump for instance), which is basically a list of command and completion function pairs, plus a huge autoload invocation registering all the completion functions. This way zsh knows which function to load when a command needs completion.
[1] https://zsh.sourceforge.io/Doc/Release/Completion-System.htm...