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

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



On Sat, Nov 27, 2021 at 12:33 AM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
> On Sat, Nov 27, 2021 at 9:11 AM Zach Riggle <zachriggle@xxxxxxxxx> 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.




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