From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Peng Yu <pengyu.ut@gmail.com>
Cc: Sebastian Gniazdowski <sgniazdowski@gmail.com>,
julien.nicoulaud@gmail.com, zsh-users <zsh-users@zsh.org>
Subject: Re: slow startup of zsh (1x slower than bash)
Date: Fri, 6 Sep 2019 16:10:31 +0200 [thread overview]
Message-ID: <CAN=4vMrz=NAqX7trSVU4iCdmq3hikLr1_2eXzkg4MFTUOPou3w@mail.gmail.com> (raw)
In-Reply-To: <CABrM6wnQhsy6pt7YixsVJakWky0jQ78Eybtb9gGFh_Puu+SGuA@mail.gmail.com>
On Fri, Sep 6, 2019 at 3:44 PM Peng Yu <pengyu.ut@gmail.com> 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.
prev parent reply other threads:[~2019-09-06 14:11 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-03 16:27 Peng Yu
2018-12-03 17:37 ` Vadim A. Misbakh-Soloviov
2018-12-07 2:19 ` Sebastian Gniazdowski
2018-12-07 2:57 ` Peng Yu
2018-12-07 16:13 ` Julien Nicoulaud
2018-12-07 16:58 ` Peng Yu
2018-12-07 18:06 ` dana
2019-09-04 10:13 ` Peng Yu
2019-09-05 19:00 ` Roman Perepelitsa
2019-09-05 20:30 ` Peng Yu
2019-09-05 20:37 ` Roman Perepelitsa
2019-09-05 20:45 ` Peng Yu
2019-09-05 21:19 ` Kaio Augusto
2019-09-06 9:35 ` Roman Perepelitsa
2019-09-06 12:57 ` Peng Yu
2019-09-06 13:11 ` Roman Perepelitsa
2019-09-06 13:19 ` Sebastian Gniazdowski
2019-09-06 13:44 ` Peng Yu
2019-09-06 14:10 ` Roman Perepelitsa [this message]
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=4vMrz=NAqX7trSVU4iCdmq3hikLr1_2eXzkg4MFTUOPou3w@mail.gmail.com' \
--to=roman.perepelitsa@gmail.com \
--cc=julien.nicoulaud@gmail.com \
--cc=pengyu.ut@gmail.com \
--cc=sgniazdowski@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).