Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Shell startup, aliases vs. functions vs. autoloadable functions, and zcompile benefits



> If first_prompt_lag of your shell is 600ms, zcompiling won't have noticeable effects

Definitely agreed.  Fortunately, you can redefine "source" as a function and trap all calls and measure how long it takes to load each file.

function source () {
    local __before="$EPOCHREALTIME"
    builtin source "$@"
    local __after="$EPOCHREALTIME"
    local __ms="$(( (__after - __before) * 1000 ))"
    echo "$__ms $@" >>| /tmp/zprezto-bench.$$.txt
}

In my case this narrowed it down pretty easily to some of the larger functions that were getting parsed on shell-startup (deferring to autoloaded functions being key).  Oddly, there is one source'd script that seems to consistently have an issue with measurement of $EPOCHREALTIME.

I've managed to get first-prompt time down to ~300ms from ~650ms, and the rest is a toss-up.  0.3s is fast enough for a login prompt for me!

$ rm -f /tmp/zprez* ; zsh -il -c exit; cat /tmp/zprez* | sort -rn | head
1638284631932.147 /Users/zachriggle/.zprezto/modules/zsh-z/init.zsh
119.97294425964355 /Users/zachriggle/.zprezto/modules/redacted1/init.zsh
85.247993469238281 /Users/zachriggle/.zprezto/modules/zach-riggle/init.zsh
47.258853912353516 /Users/zachriggle/.zprezto/modules/completion/init.zsh
30.105113983154297 /Users/zachriggle/.zprezto/modules/prompt/init.zsh
23.977041244506836 /Users/zachriggle/.zprezto/modules/redacted2/scripts/init.zsh
20.226001739501953 /Users/zachriggle/.zprezto/modules/zach-riggle/path.zsh
19.911050796508789 /Users/zachriggle/.zprezto/modules/syntax-highlighting/init.zsh
19.558191299438477 /Users/zachriggle/.zprezto/modules/syntax-highlighting/external/zsh-syntax-highlighting.zsh

Zach Riggle



On Tue, Nov 30, 2021 at 6:30 AM Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx> wrote:
On Tue, Nov 30, 2021 at 12:49 PM Zach Riggle <zachriggle@xxxxxxxxx> wrote:
>
> > FWIW, I zcompile my own rc files
>
> What is the optimal way to compile a huge set of them?

Most of the zsh files you are using are *installed* rather than
modified by yourself. You can zcompile them when you install/update
them. E.g., you have some code that installs/updates prezto. Invoke
zcompile in there.

There are also zsh startup files that you modify manually every now
and then (.zshrc, etc.). Compiling these files is harder and is more
likely to cause issues. On the other hand, the benefits of compiling
them are tiny, simply because those files are tiny. Once again, you
can manually zcompile different things and check whether you notice
any difference. If you don't, there is no need to invest in
zcompiling.

If first_prompt_lag of your shell is 600ms, zcompiling won't have
noticeable effects. You'll need to optimize other things first for
zcompiling to matter.

Roman.


Messages sorted by: Reverse Date, Date, Thread, Author