zsh-users
 help / color / mirror / code / Atom feed
From: Zach Riggle <zachriggle@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Shell startup, aliases vs. functions vs. autoloadable functions, and zcompile benefits
Date: Mon, 29 Nov 2021 20:30:12 -0600	[thread overview]
Message-ID: <CAMP9c5=nQS_cw19fuKhKMJAAVPwEr5oCNUiBDBCWBiPC1KioWw@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7ZuG0z7m5_z8qCaGiCpDO0KRvXHWz3jkighvkaFcd6+LA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2763 bytes --]

Good points all around!  I did play around with hyperfine compiling all zsh
scripts in ~/.zprezto and didn't see a tangible difference.

The benchmark I used

$ hyperfine 'zsh -i -l "exit 0"'


Obviously this is not the BEST benchmark, but it is useful for checking
shell startup time -- I might give zsh-bench a look.  I did spend a lot of
time with zprof to benchmark my init scripts, but the most time-consuming
is simply the "source" statement loading other things, but there's no
context as to WHICH files being sourced take the most time.

> you might end up with a mismatched zwc with greater mtime.

This is something I expected to cause hard-to-diagnose problems.  Luckily,
the most common way I'd change files inadvertently (git checkout
branchname) does not use the time from the commit.

I would expect that the md5sum of a file is reasonably fast, and could be
stored in the .zwc for sanity checking, instead of just the "newer than"
check.

> Again you're unlikely to notice unless your $fpath entries are numerous
and deep

> The tradeoff is that the third one occupies less memory than either of
the other two (though about the same as the alias) which is significant if
there are a lot of seldom-used functions.

I expect that I have more $fpath entries than usual, but the total number
of autoloadable functions is much more.

$ echo $#fpath
22

$ for d in $fpath; do n=$(ls $d/* | wc -l); echo "$n $d"; done | sort -nr |
head -3
    1162 /usr/share/zsh/5.8/functions
     559 /usr/share/zsh/site-functions
     141 /Users/zachriggle/.zprezto/modules/completion/external/src


*Zach Riggle*


On Sat, Nov 27, 2021 at 2:22 PM Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Sat, Nov 27, 2021 at 12:33 AM Roman Perepelitsa
> <roman.perepelitsa@gmail.com> wrote:
> >
> > On Sat, Nov 27, 2021 at 9:11 AM Zach Riggle <zachriggle@gmail.com>
> wrote:
> > >
> > > alias foo='foo --flag1 --flag2'
> > > foo() { command foo --flag1 --flag2 "$@" }
> > > autoloadable module containing (2)
> >
> > In theory the first and the last should have the same performance and
> > the middle should be slower because it has to parse the body. In
> > practice you won't find any difference: zsh parser is very fast.
>
> This is true for shell startup time; at runtime there's a small
> penalty for the middle one (allocating the function context) and on
> the very first execution there's an additional load-time cost for the
> third one.  Again you're unlikely to notice unless your $fpath entries
> are numerous and deep.
>
> The tradeoff is that the third one occupies less memory than either of
> the other two (though about the same as the alias) which is
> significant if there are a lot of seldom-used functions.
>
> Otherwise, everything Roman said.
>

[-- Attachment #2: Type: text/html, Size: 4893 bytes --]

  reply	other threads:[~2021-11-30  2:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-27  8:10 Zach Riggle
2021-11-27  8:33 ` Roman Perepelitsa
2021-11-27 20:22   ` Bart Schaefer
2021-11-30  2:30     ` Zach Riggle [this message]
2021-11-30  4:11       ` Bart Schaefer
2021-11-30  8:18         ` Zach Riggle
2021-11-30  7:51       ` Roman Perepelitsa
2021-11-30  8:10         ` Mikael Magnusson
2021-11-30  8:27           ` Mikael Magnusson
2021-11-30  8:30             ` Zach Riggle
2021-11-30  9:11             ` Roman Perepelitsa
2021-11-30 11:49               ` Zach Riggle
2021-11-30 12:30                 ` Roman Perepelitsa
2021-11-30 15:10                   ` Zach Riggle
2021-11-30 16:37                     ` Bart Schaefer
2021-11-30 16:41                       ` Roman Perepelitsa
2021-11-30  8:29           ` Roman Perepelitsa
2021-11-30  8:25         ` Zach Riggle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMP9c5=nQS_cw19fuKhKMJAAVPwEr5oCNUiBDBCWBiPC1KioWw@mail.gmail.com' \
    --to=zachriggle@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).