zsh-users
 help / color / mirror / code / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Zach Riggle <zachriggle@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Shell startup, aliases vs. functions vs. autoloadable functions, and zcompile benefits
Date: Sat, 27 Nov 2021 09:33:25 +0100	[thread overview]
Message-ID: <CAN=4vMpyybbN-DTT7eAXdxV_a=CtaEcaNTKEszQjgL8urTY_zg@mail.gmail.com> (raw)
In-Reply-To: <CAMP9c5=AkW8B0byaw9J-_rVJ0B19q9xx3wjz3MAgJr6uCF6vNQ@mail.gmail.com>

On Sat, Nov 27, 2021 at 9:11 AM Zach Riggle <zachriggle@gmail.com> wrote:
>
> Does anybody have information on which approach is faster?
>
> 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.

There is a difference in usability between these options. When using
an alias, you can expand it (provided that you have a binding for
expanding aliases) to check what it does and then either undo the
expansion (provided you have a binding) or modify it. I do this all
the time. Aliases also allow you to bypass them with `\foo` rather
than `command foo`. Less typing.

> Finally, I'm aware of the zcompile tool to create .zwc bytecode files, but it appears that this causes issues with $functions / $functions_source and sometimes things don't work.

zcompiling has two main gotchas:

1. Aliases get expanded differently.
2. If you move a source file (e.g., to backup) and then move it back
(restore from backup), you might end up with a mismatched zwc with
greater mtime.

See https://github.com/romkatv/zsh-bench#cutting-corners for a more
detailed description.

> Is there a true performance benefit in the general case for pre-compiling ALL of my zsh scripts (i.e. everything inside ~/.zprezto that /usr/bin/file says is a "zsh script text executable")?

The only benefit of zcompiling is performance. For autoloadable
functions that don't get invoked on startup you won't be able to tell
the difference. This means that the only benefit of zcompiling is
faster zsh startup. You can simply try it: zcompile your stuff and see
if you can tell the difference in zsh startup speed using your own
senses. If you cannot, there is no point in zcompiling. If you want a
machine-mediated measurement, you can use
https://github.com/romkatv/zsh-bench and look at first_prompt_lag and
first_command_lag in the output.

Roman.


  reply	other threads:[~2021-11-27  8:34 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 [this message]
2021-11-27 20:22   ` Bart Schaefer
2021-11-30  2:30     ` Zach Riggle
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='CAN=4vMpyybbN-DTT7eAXdxV_a=CtaEcaNTKEszQjgL8urTY_zg@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --cc=zachriggle@gmail.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).