Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: slow startup of zsh (1x slower than bash)
- X-seq: zsh-users 24217
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Peng Yu <pengyu.ut@xxxxxxxxx>
- Subject: Re: slow startup of zsh (1x slower than bash)
- Date: Fri, 6 Sep 2019 16:10:31 +0200
- Cc: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>, julien.nicoulaud@xxxxxxxxx, zsh-users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=/PcXF21p16FArzYURz9cIfl0Ki0UlYNswm8AJvZZAso=; b=Rpw4md24eyqcxYSMybR2ftgRLNlXfNlNdcnM9Zs8sGehDU/1K20E0KQSSvGV6dGoPV ux70Y5uzSfa+5NTiMRrHnApxxRfioGWENuee/UM0t/mazisznjqtFBJxwD3eeo6vptoe QHhSpIs3Bl/4Dei3WlktDNE6iVBSpPD0tXNG2CbR9JSHnfrnur08YQxsUuiHMegYef+Z ucYZpSKIJyD7diVKu5pSnK9rbCebGgCsAuuBpybDtg3OEdRGTrjj9XbxOGHO2374DgEg fm1v5xZqIA39Yqq1j4SBinn8JIYhi2QVSS51g8/zfH9LOG9NBukrCPEBivTsAZlutq9T 1o+A==
- In-reply-to: <CABrM6wnQhsy6pt7YixsVJakWky0jQ78Eybtb9gGFh_Puu+SGuA@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CABrM6wk-psFFZcZW+M7OwD0ZwrMbNk4MN7e9aaJF9kBOFsVK4w@mail.gmail.com> <CAKc7PVDGmfMxkUzjmyFxJY7fNhHV16Z3xhQpNXnjEwAMf6G9hQ@mail.gmail.com> <CABrM6w=B8BP6Pk4HsW+XGDv0bpC9fYtNdr80SS6BtqegXJNcUA@mail.gmail.com> <CA+mcLN5dpscPNhpsKoA0j8tvcUh2-A7KOX7wNQYFQ7q3sdg+SA@mail.gmail.com> <CABrM6wkGd4=ikqoZOreovU95MpPe1fparZ+5qse-8fZ4M=3-OQ@mail.gmail.com> <CABrM6wk+PG2jopGJ8OqpUz-yaXqKet6aZJk2Oc7jZbjS3kWa9A@mail.gmail.com> <CAN=4vMrczC24GEH45UBaOtQY7rthiyWupmhPdJA+VgKuBnzobg@mail.gmail.com> <CABrM6wkvrMSpT=R22XYyA27hbqG75AyEuiamro9=Qs5kx2Skhg@mail.gmail.com> <CAN=4vMqS0o6QBOXXxPL2dCJGQLv+t61B0R+=eUSXaai3qgA4hQ@mail.gmail.com> <CABrM6w=0LBy99ePvChBe22v3XZ=JfY_Tbu0Guf8z6zcyALER3Q@mail.gmail.com> <CAN=4vMoYDBiYFdpo9v7OG_03DzjGPDGHww_0_wDsc3cbqwndJQ@mail.gmail.com> <CABrM6w=z3-w7U=MCJrHfVnQe9nk0G3c3fCbhKBPb_ye3u_YaGA@mail.gmail.com> <CAN=4vMommtG_dPmfhWS4VXY-er9QxL4AKY70o-eR7TGw-ejzkA@mail.gmail.com> <CABrM6wnQhsy6pt7YixsVJakWky0jQ78Eybtb9gGFh_Puu+SGuA@mail.gmail.com>
On Fri, Sep 6, 2019 at 3:44 PM Peng Yu <pengyu.ut@xxxxxxxxx> wrote:
> I build a library that one causes another. In such cases, the
> startup time matters, as most of scripts don’t take a long
> time to run, I don’t want the startup eat up too much time.
> I know I can use ‘source’ circumvent this problem to a certain extent.
Autoloading was designed to solve this problem (among others). Give it
a try. Your zsh scripts might become orders of magnitude faster than
in bash and you don't even have to change them.
For example, suppose you have two files in your ~/bin:
% cat ~/bin/greet
#!/usr/bin/env zsh
print -r "Hello, $1"
% cat ~/bin/spam
#!/usr/bin/env zsh
repeat $1 greet $2
Let's further suppose that ~/bin is in your $PATH.
% spam 3 $USER
Hello, romka
Hello, romka
Hello, romka
You can make greet and spam much faster by adding these two lines to
your ~/.zshrc:
fpath+=~/bin
autoload -Uz ~/bin/*(x:t)
On my system this simple 2-line addition to ~/.zshrc speeds up `spam 3
$USER` by a factor of 5000.
Note that you can still invoke your scripts the same way as before.
Use ~/bin/spam or =spam to force-spawn a new shell process, while the
plain spam will call a function within the same shell process. The
first call to spam will automatically source ~/bin/spam and turn it
into a function.
> But having a shorter startup time is still a good thing. If bash can
> do it, I don’t think zsh is absolutely unable to do it.
Faster is always better than slower but when there is no practical
difference then the development effort might be better spent
elsewhere. Everyone's environment is different but from my point of
view zsh startup is fast enough to be indistinguishable from zero.
Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author