zsh-users
 help / color / mirror / code / Atom feed
* slow startup of zsh (1x slower than bash)
@ 2018-12-03 16:27 Peng Yu
  2018-12-03 17:37 ` Vadim A. Misbakh-Soloviov
  2018-12-07  2:19 ` Sebastian Gniazdowski
  0 siblings, 2 replies; 19+ messages in thread
From: Peng Yu @ 2018-12-03 16:27 UTC (permalink / raw)
  To: zsh-users

Hi,

The following example shows that zsh startup time is much slower than
other shells. Can this be improved to at least as fast as bash?

==> main.sh <==
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

set -v
TIMEFORMAT=%R
time for ((i=0;i<100;++i))
do
    :
done
time for ((i=0;i<100;++i))
do
    ./script.sh
done
time for ((i=0;i<100;++i))
do
    ./script.dash
done
time for ((i=0;i<100;++i))
do
    ./script.bash
done
time for ((i=0;i<100;++i))
do
    ./script.ksh
done
time for ((i=0;i<100;++i))
do
    ./script.zsh
done
==> script.bash <==
#!/usr/local/bin/bash
==> script.dash <==
#!/usr/local/bin/dash
==> script.ksh <==
#!/usr/local/bin/ksh
==> script.sh <==
#!/bin/sh
==> script.zsh <==
#!/usr/local/bin/zsh
$ ./main.sh
TIMEFORMAT=%R
time for ((i=0;i<100;++i))
do
    :
done
0.001
time for ((i=0;i<100;++i))
do
    ./script.sh
done
0.339
time for ((i=0;i<100;++i))
do
    ./script.dash
done
0.387
time for ((i=0;i<100;++i))
do
    ./script.bash
done
0.486
time for ((i=0;i<100;++i))
do
    ./script.ksh
done
0.538
time for ((i=0;i<100;++i))
do
    ./script.zsh
done
0.953

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  2018-12-03 16:27 slow startup of zsh (1x slower than bash) Peng Yu
@ 2018-12-03 17:37 ` Vadim A. Misbakh-Soloviov
  2018-12-07  2:19 ` Sebastian Gniazdowski
  1 sibling, 0 replies; 19+ messages in thread
From: Vadim A. Misbakh-Soloviov @ 2018-12-03 17:37 UTC (permalink / raw)
  To: zsh-users

try to put "zsh -f" there, instead of just "zsh", and take a look at the time 
after that.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  2018-12-03 16:27 slow startup of zsh (1x slower than bash) 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
  1 sibling, 1 reply; 19+ messages in thread
From: Sebastian Gniazdowski @ 2018-12-07  2:19 UTC (permalink / raw)
  To: pengyu.ut; +Cc: Zsh Users

On Mon, 3 Dec 2018 at 17:28, Peng Yu <pengyu.ut@gmail.com> wrote:
>
> Hi,
>
> The following example shows that zsh startup time is much slower than
> other shells. Can this be improved to at least as fast as bash?
>

Is it the last zsh version that's being tested? There was 2x startup
improvement at 5.4 or something like this.

Also, Zplugin can load plugins after prompt, I load 20 plugins, and my
startup times are:

repeat 5 { time /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit }
/usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,09s user 0,04s system
117% cpu 0,111 total
/usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,10s user 0,05s system
119% cpu 0,130 total
/usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,11s user 0,05s system
121% cpu 0,129 total
/usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,09s user 0,04s system
115% cpu 0,119 total
/usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,09s user 0,04s system
117% cpu 0,109 total

I even load prompt after a default prompt, ~ 100 ms after it. The
Star-Trek console-like impression this gives can be visible here:
https://asciinema.org/a/156726 – much is going on, automatically, in
background.

> --
> Regards,
> Peng

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  2018-12-07  2:19 ` Sebastian Gniazdowski
@ 2018-12-07  2:57   ` Peng Yu
  2018-12-07 16:13     ` Julien Nicoulaud
  0 siblings, 1 reply; 19+ messages in thread
From: Peng Yu @ 2018-12-07  2:57 UTC (permalink / raw)
  To: sgniazdowski; +Cc: zsh-users

On Thu, Dec 6, 2018 at 8:20 PM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> On Mon, 3 Dec 2018 at 17:28, Peng Yu <pengyu.ut@gmail.com> wrote:
> >
> > Hi,
> >
> > The following example shows that zsh startup time is much slower than
> > other shells. Can this be improved to at least as fast as bash?
> >
>
> Is it the last zsh version that's being tested? There was 2x startup
> improvement at 5.4 or something like this.

Here is the version. I have not set up zsh to do anything fancy. I
guess the slowness of startup is because zsh does too many things
upfront and has more features than other shells, and the increase in
startup time the price that zsh has to pay.

$ zsh --version
zsh 5.6.2 (x86_64-apple-darwin17.7.0)
$ cat ~/.zshrc
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
bindkey -e
# End of lines configured by zsh-newuser-install
# The following lines were added by compinstall
zstyle :compinstall filename '/Users/pengy/.zshrc'

autoload -Uz compinit
compinit
# End of lines added by compinstall

> Also, Zplugin can load plugins after prompt, I load 20 plugins, and my
> startup times are:
>
> repeat 5 { time /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit }
> /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,09s user 0,04s system
> 117% cpu 0,111 total
> /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,10s user 0,05s system
> 119% cpu 0,130 total
> /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,11s user 0,05s system
> 121% cpu 0,129 total
> /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,09s user 0,04s system
> 115% cpu 0,119 total
> /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,09s user 0,04s system
> 117% cpu 0,109 total
>
> I even load prompt after a default prompt, ~ 100 ms after it. The
> Star-Trek console-like impression this gives can be visible here:
> https://asciinema.org/a/156726 – much is going on, automatically, in
> background.
>
> > --
> > Regards,
> > Peng
>
> --
> Sebastian Gniazdowski
> News: https://twitter.com/ZdharmaI
> IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
> Blog: http://zdharma.org



-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  2018-12-07  2:57   ` Peng Yu
@ 2018-12-07 16:13     ` Julien Nicoulaud
  2018-12-07 16:58       ` Peng Yu
  0 siblings, 1 reply; 19+ messages in thread
From: Julien Nicoulaud @ 2018-12-07 16:13 UTC (permalink / raw)
  To: pengyu.ut; +Cc: sgniazdowski, Mailing-list zsh-users

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

I don't think so, zsh is faster than bash for me without rc files:

❯ repeat 5 { time bash --norc --noprofile -c exit }
took 0,011s (100% cpu)
took 0,011s (98% cpu)
took 0,011s (100% cpu)
took 0,011s (100% cpu)
took 0,011s (99% cpu)
❯ repeat 5 { time zsh -fc exit }
took 0,002s (89% cpu)
took 0,001s (90% cpu)
took 0,001s (92% cpu)
took 0,001s (92% cpu)
took 0,001s (91% cpu)

same with rc files:
❯ repeat 5 { time bash -c exit }
took 0,028s (89% cpu)
took 0,022s (100% cpu)
took 0,022s (100% cpu)
took 0,022s (100% cpu)
took 0,023s (99% cpu)
❯ repeat 5 { time zsh -c exit }
took 0,008s (91% cpu)
took 0,008s (92% cpu)
took 0,007s (92% cpu)
took 0,007s (92% cpu)
took 0,005s (91% cpu)

Julien

Le ven. 7 déc. 2018 à 03:57, Peng Yu <pengyu.ut@gmail.com> a écrit :

> On Thu, Dec 6, 2018 at 8:20 PM Sebastian Gniazdowski
> <sgniazdowski@gmail.com> wrote:
> >
> > On Mon, 3 Dec 2018 at 17:28, Peng Yu <pengyu.ut@gmail.com> wrote:
> > >
> > > Hi,
> > >
> > > The following example shows that zsh startup time is much slower than
> > > other shells. Can this be improved to at least as fast as bash?
> > >
> >
> > Is it the last zsh version that's being tested? There was 2x startup
> > improvement at 5.4 or something like this.
>
> Here is the version. I have not set up zsh to do anything fancy. I
> guess the slowness of startup is because zsh does too many things
> upfront and has more features than other shells, and the increase in
> startup time the price that zsh has to pay.
>
> $ zsh --version
> zsh 5.6.2 (x86_64-apple-darwin17.7.0)
> $ cat ~/.zshrc
> # Lines configured by zsh-newuser-install
> HISTFILE=~/.histfile
> HISTSIZE=1000
> SAVEHIST=1000
> bindkey -e
> # End of lines configured by zsh-newuser-install
> # The following lines were added by compinstall
> zstyle :compinstall filename '/Users/pengy/.zshrc'
>
> autoload -Uz compinit
> compinit
> # End of lines added by compinstall
>
> > Also, Zplugin can load plugins after prompt, I load 20 plugins, and my
> > startup times are:
> >
> > repeat 5 { time /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit }
> > /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,09s user 0,04s system
> > 117% cpu 0,111 total
> > /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,10s user 0,05s system
> > 119% cpu 0,130 total
> > /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,11s user 0,05s system
> > 121% cpu 0,129 total
> > /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,09s user 0,04s system
> > 115% cpu 0,119 total
> > /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,09s user 0,04s system
> > 117% cpu 0,109 total
> >
> > I even load prompt after a default prompt, ~ 100 ms after it. The
> > Star-Trek console-like impression this gives can be visible here:
> > https://asciinema.org/a/156726 – much is going on, automatically, in
> > background.
> >
> > > --
> > > Regards,
> > > Peng
> >
> > --
> > Sebastian Gniazdowski
> > News: https://twitter.com/ZdharmaI
> > IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
> > Blog: http://zdharma.org
>
>
>
> --
> Regards,
> Peng
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  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
  0 siblings, 2 replies; 19+ messages in thread
From: Peng Yu @ 2018-12-07 16:58 UTC (permalink / raw)
  To: julien.nicoulaud; +Cc: Sebastian Gniazdowski, zsh-users

Not on my machine.

$ ./main.sh
time ./script.bash

real    0m0.719s
user    0m0.264s
sys    0m0.324s
time ./script.zsh

real    0m1.295s
user    0m0.360s
sys    0m0.680s

==> main.sh <==
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

set -v
time ./script.bash
time ./script.zsh

==> script.bash <==
#!/usr/bin/env zsh
# vim: set noexpandtab tabstop=2:

time for ((i=0;i<100;++i))
do
    /usr/local/bin/bash --norc --noprofile -c exit
done

==> script.zsh <==
#!/usr/bin/env zsh
# vim: set noexpandtab tabstop=2:

time for ((i=0;i<100;++i))
do
    /usr/local/bin/zsh -fc exit
done


On Fri, Dec 7, 2018 at 10:14 AM Julien Nicoulaud
<julien.nicoulaud@gmail.com> wrote:
>
> I don't think so, zsh is faster than bash for me without rc files:
>
> ❯ repeat 5 { time bash --norc --noprofile -c exit }
> took 0,011s (100% cpu)
> took 0,011s (98% cpu)
> took 0,011s (100% cpu)
> took 0,011s (100% cpu)
> took 0,011s (99% cpu)
> ❯ repeat 5 { time zsh -fc exit }
> took 0,002s (89% cpu)
> took 0,001s (90% cpu)
> took 0,001s (92% cpu)
> took 0,001s (92% cpu)
> took 0,001s (91% cpu)
>
> same with rc files:
> ❯ repeat 5 { time bash -c exit }
> took 0,028s (89% cpu)
> took 0,022s (100% cpu)
> took 0,022s (100% cpu)
> took 0,022s (100% cpu)
> took 0,023s (99% cpu)
> ❯ repeat 5 { time zsh -c exit }
> took 0,008s (91% cpu)
> took 0,008s (92% cpu)
> took 0,007s (92% cpu)
> took 0,007s (92% cpu)
> took 0,005s (91% cpu)
>
> Julien
>
> Le ven. 7 déc. 2018 à 03:57, Peng Yu <pengyu.ut@gmail.com> a écrit :
>>
>> On Thu, Dec 6, 2018 at 8:20 PM Sebastian Gniazdowski
>> <sgniazdowski@gmail.com> wrote:
>> >
>> > On Mon, 3 Dec 2018 at 17:28, Peng Yu <pengyu.ut@gmail.com> wrote:
>> > >
>> > > Hi,
>> > >
>> > > The following example shows that zsh startup time is much slower than
>> > > other shells. Can this be improved to at least as fast as bash?
>> > >
>> >
>> > Is it the last zsh version that's being tested? There was 2x startup
>> > improvement at 5.4 or something like this.
>>
>> Here is the version. I have not set up zsh to do anything fancy. I
>> guess the slowness of startup is because zsh does too many things
>> upfront and has more features than other shells, and the increase in
>> startup time the price that zsh has to pay.
>>
>> $ zsh --version
>> zsh 5.6.2 (x86_64-apple-darwin17.7.0)
>> $ cat ~/.zshrc
>> # Lines configured by zsh-newuser-install
>> HISTFILE=~/.histfile
>> HISTSIZE=1000
>> SAVEHIST=1000
>> bindkey -e
>> # End of lines configured by zsh-newuser-install
>> # The following lines were added by compinstall
>> zstyle :compinstall filename '/Users/pengy/.zshrc'
>>
>> autoload -Uz compinit
>> compinit
>> # End of lines added by compinstall
>>
>> > Also, Zplugin can load plugins after prompt, I load 20 plugins, and my
>> > startup times are:
>> >
>> > repeat 5 { time /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit }
>> > /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,09s user 0,04s system
>> > 117% cpu 0,111 total
>> > /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,10s user 0,05s system
>> > 119% cpu 0,130 total
>> > /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,11s user 0,05s system
>> > 121% cpu 0,129 total
>> > /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,09s user 0,04s system
>> > 115% cpu 0,119 total
>> > /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,09s user 0,04s system
>> > 117% cpu 0,109 total
>> >
>> > I even load prompt after a default prompt, ~ 100 ms after it. The
>> > Star-Trek console-like impression this gives can be visible here:
>> > https://asciinema.org/a/156726 – much is going on, automatically, in
>> > background.
>> >
>> > > --
>> > > Regards,
>> > > Peng
>> >
>> > --
>> > Sebastian Gniazdowski
>> > News: https://twitter.com/ZdharmaI
>> > IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
>> > Blog: http://zdharma.org
>>
>>
>>
>> --
>> Regards,
>> Peng



-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  2018-12-07 16:58       ` Peng Yu
@ 2018-12-07 18:06         ` dana
  2019-09-04 10:13         ` Peng Yu
  1 sibling, 0 replies; 19+ messages in thread
From: dana @ 2018-12-07 18:06 UTC (permalink / raw)
  To: Peng Yu; +Cc: julien.nicoulaud, Sebastian Gniazdowski, zsh-users

Some of the people on #zsh have seen different results, but `zsh -f`'s start-up
over-head has always been higher for me on every platform i've tested
(specifically Linux@ARM, Linux@x64, and macOS@x64). It's especially noticeable
on the Mac — but all process over-heads are exaggerated on the Mac, so.

I don't worry about it too much, because you make up for it as soon as you're
able to do something that would have required a fork() in another shell, like
sorting an array or resolving a symlink or matching files by attributes.

I suppose it might be annoying to use it for an httpd or Make shell though

dana


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  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
  1 sibling, 1 reply; 19+ messages in thread
From: Peng Yu @ 2019-09-04 10:13 UTC (permalink / raw)
  To: julien.nicoulaud; +Cc: Sebastian Gniazdowski, zsh-users

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

Are there any consensus on how fast is zsh starting time compared with
other shells? My test was on Mac via homebrew.

On Fri, Dec 7, 2018 at 10:58 AM Peng Yu <pengyu.ut@gmail.com> wrote:

> Not on my machine.
>
> $ ./main.sh
> time ./script.bash
>
> real    0m0.719s
> user    0m0.264s
> sys    0m0.324s
> time ./script.zsh
>
> real    0m1.295s
> user    0m0.360s
> sys    0m0.680s
>
> ==> main.sh <==
> #!/usr/bin/env bash
> # vim: set noexpandtab tabstop=2:
>
> set -v
> time ./script.bash
> time ./script.zsh
>
> ==> script.bash <==
> #!/usr/bin/env zsh
> # vim: set noexpandtab tabstop=2:
>
> time for ((i=0;i<100;++i))
> do
>     /usr/local/bin/bash --norc --noprofile -c exit
> done
>
> ==> script.zsh <==
> #!/usr/bin/env zsh
> # vim: set noexpandtab tabstop=2:
>
> time for ((i=0;i<100;++i))
> do
>     /usr/local/bin/zsh -fc exit
> done
>
>
> On Fri, Dec 7, 2018 at 10:14 AM Julien Nicoulaud
> <julien.nicoulaud@gmail.com> wrote:
> >
> > I don't think so, zsh is faster than bash for me without rc files:
> >
> > ❯ repeat 5 { time bash --norc --noprofile -c exit }
> > took 0,011s (100% cpu)
> > took 0,011s (98% cpu)
> > took 0,011s (100% cpu)
> > took 0,011s (100% cpu)
> > took 0,011s (99% cpu)
> > ❯ repeat 5 { time zsh -fc exit }
> > took 0,002s (89% cpu)
> > took 0,001s (90% cpu)
> > took 0,001s (92% cpu)
> > took 0,001s (92% cpu)
> > took 0,001s (91% cpu)
> >
> > same with rc files:
> > ❯ repeat 5 { time bash -c exit }
> > took 0,028s (89% cpu)
> > took 0,022s (100% cpu)
> > took 0,022s (100% cpu)
> > took 0,022s (100% cpu)
> > took 0,023s (99% cpu)
> > ❯ repeat 5 { time zsh -c exit }
> > took 0,008s (91% cpu)
> > took 0,008s (92% cpu)
> > took 0,007s (92% cpu)
> > took 0,007s (92% cpu)
> > took 0,005s (91% cpu)
> >
> > Julien
> >
> > Le ven. 7 déc. 2018 à 03:57, Peng Yu <pengyu.ut@gmail.com> a écrit :
> >>
> >> On Thu, Dec 6, 2018 at 8:20 PM Sebastian Gniazdowski
> >> <sgniazdowski@gmail.com> wrote:
> >> >
> >> > On Mon, 3 Dec 2018 at 17:28, Peng Yu <pengyu.ut@gmail.com> wrote:
> >> > >
> >> > > Hi,
> >> > >
> >> > > The following example shows that zsh startup time is much slower
> than
> >> > > other shells. Can this be improved to at least as fast as bash?
> >> > >
> >> >
> >> > Is it the last zsh version that's being tested? There was 2x startup
> >> > improvement at 5.4 or something like this.
> >>
> >> Here is the version. I have not set up zsh to do anything fancy. I
> >> guess the slowness of startup is because zsh does too many things
> >> upfront and has more features than other shells, and the increase in
> >> startup time the price that zsh has to pay.
> >>
> >> $ zsh --version
> >> zsh 5.6.2 (x86_64-apple-darwin17.7.0)
> >> $ cat ~/.zshrc
> >> # Lines configured by zsh-newuser-install
> >> HISTFILE=~/.histfile
> >> HISTSIZE=1000
> >> SAVEHIST=1000
> >> bindkey -e
> >> # End of lines configured by zsh-newuser-install
> >> # The following lines were added by compinstall
> >> zstyle :compinstall filename '/Users/pengy/.zshrc'
> >>
> >> autoload -Uz compinit
> >> compinit
> >> # End of lines added by compinstall
> >>
> >> > Also, Zplugin can load plugins after prompt, I load 20 plugins, and my
> >> > startup times are:
> >> >
> >> > repeat 5 { time /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit }
> >> > /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,09s user 0,04s system
> >> > 117% cpu 0,111 total
> >> > /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,10s user 0,05s system
> >> > 119% cpu 0,130 total
> >> > /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,11s user 0,05s system
> >> > 121% cpu 0,129 total
> >> > /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,09s user 0,04s system
> >> > 115% cpu 0,119 total
> >> > /usr/local/bin/zsh-5.6.2-dev-1 -i -c exit  0,09s user 0,04s system
> >> > 117% cpu 0,109 total
> >> >
> >> > I even load prompt after a default prompt, ~ 100 ms after it. The
> >> > Star-Trek console-like impression this gives can be visible here:
> >> > https://asciinema.org/a/156726 – much is going on, automatically, in
> >> > background.
> >> >
> >> > > --
> >> > > Regards,
> >> > > Peng
> >> >
> >> > --
> >> > Sebastian Gniazdowski
> >> > News: https://twitter.com/ZdharmaI
> >> > IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
> >> > Blog: http://zdharma.org
> >>
> >>
> >>
> >> --
> >> Regards,
> >> Peng
>
>
>
> --
> Regards,
> Peng
>
-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  2019-09-04 10:13         ` Peng Yu
@ 2019-09-05 19:00           ` Roman Perepelitsa
  2019-09-05 20:30             ` Peng Yu
  0 siblings, 1 reply; 19+ messages in thread
From: Roman Perepelitsa @ 2019-09-05 19:00 UTC (permalink / raw)
  To: Peng Yu; +Cc: julien.nicoulaud, Sebastian Gniazdowski, zsh-users

On Wed, Sep 4, 2019 at 12:15 PM Peng Yu <pengyu.ut@gmail.com> wrote:
>
> Are there any consensus on how fast is zsh starting time compared with
> other shells? My test was on Mac via homebrew.

You need to pass -d to zsh to make benchmarks fair. Otherwise zsh is
sourcing global configs while bash doesn't.

    time ( repeat 1000 zsh -df -c '' )
    time ( repeat 1000 bash -c '' )

I get 4 ms and 3 ms for zsh and bash respectively.

Note that this number has virtually no bearing on interactive shell
startup time.

Roman.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  2019-09-05 19:00           ` Roman Perepelitsa
@ 2019-09-05 20:30             ` Peng Yu
  2019-09-05 20:37               ` Roman Perepelitsa
  0 siblings, 1 reply; 19+ messages in thread
From: Peng Yu @ 2019-09-05 20:30 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: julien.nicoulaud, Sebastian Gniazdowski, zsh-users

> You need to pass -d to zsh to make benchmarks fair.

Where is -d defined in the man page of zsh? I don't find it.

> Otherwise zsh is
> sourcing global configs while bash doesn't.
>
>     time ( repeat 1000 zsh -df -c '' )
>     time ( repeat 1000 bash -c '' )
>
> I get 4 ms and 3 ms for zsh and bash respectively.
>
> Note that this number has virtually no bearing on interactive shell
> startup time.

Here is my runtime result. There is still about 50% startup time
overhead of zsh compared to bash. This is quite significant.

time ( repeat 1000 zsh -df -c '' )
( repeat 1000; do; zsh -df -c ''; done; )  3.01s user 6.07s system 75%
cpu 12.056 total
time ( repeat 1000 bash -c '' )
( repeat 1000; do; bash -c ''; done; )  2.16s user 2.73s system 72%
cpu 6.719 total

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  2019-09-05 20:30             ` Peng Yu
@ 2019-09-05 20:37               ` Roman Perepelitsa
  2019-09-05 20:45                 ` Peng Yu
  0 siblings, 1 reply; 19+ messages in thread
From: Roman Perepelitsa @ 2019-09-05 20:37 UTC (permalink / raw)
  To: Peng Yu; +Cc: julien.nicoulaud, Sebastian Gniazdowski, zsh-users

On Thu, Sep 5, 2019 at 10:30 PM Peng Yu <pengyu.ut@gmail.com> wrote:
>
> > You need to pass -d to zsh to make benchmarks fair.
>
> Where is -d defined in the man page of zsh? I don't find it.

From `zsh --help`:

  -d    equivalent to --no-globalrcs

> Here is my runtime result. There is still about 50% startup time
> overhead of zsh compared to bash. This is quite significant.

What are you trying to optimize? If you care about the startup time of
your interactive shell, 12 ms vs 6.7 ms doesn't make a difference.

Roman.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  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
  0 siblings, 2 replies; 19+ messages in thread
From: Peng Yu @ 2019-09-05 20:45 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: julien.nicoulaud, Sebastian Gniazdowski, zsh-users

>> Where is -d defined in the man page of zsh? I don't find it.
>
> From `zsh --help`:
>
>   -d    equivalent to --no-globalrcs

Can this be found in the manpage? I don't see it.

>> Here is my runtime result. There is still about 50% startup time
>> overhead of zsh compared to bash. This is quite significant.
>
> What are you trying to optimize? If you care about the startup time of
> your interactive shell, 12 ms vs 6.7 ms doesn't make a difference.

It is not for interactive use of zsh/bash. I am making scripts using
shells. 12 vs 6.7 ms that is 1x or 50% difference depending on which
way you consider the ratio, which is a quite significant difference.


-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  2019-09-05 20:45                 ` Peng Yu
@ 2019-09-05 21:19                   ` Kaio Augusto
  2019-09-06  9:35                   ` Roman Perepelitsa
  1 sibling, 0 replies; 19+ messages in thread
From: Kaio Augusto @ 2019-09-05 21:19 UTC (permalink / raw)
  To: zsh-users

>>> Where is -d defined in the man page of zsh? I don't find it.
>>
>> From `zsh --help`:
>>
>>   -d    equivalent to --no-globalrcs
> 
> Can this be found in the manpage? I don't see it.

In manpage zshoptions(1):

GLOBAL_RCS (-d) <D>
If this option is unset, the startup files /etc/zprofile,  /etc/zshrc,
/etc/zlogin  and  /etc/zlogout will  not be run.  It can be disabled and
re-enabled at any time, including inside local startup files (.zshrc, etc.).

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  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
  1 sibling, 1 reply; 19+ messages in thread
From: Roman Perepelitsa @ 2019-09-06  9:35 UTC (permalink / raw)
  To: Peng Yu; +Cc: julien.nicoulaud, Sebastian Gniazdowski, zsh-users

On Thu, Sep 5, 2019 at 10:45 PM Peng Yu <pengyu.ut@gmail.com> wrote:
> > What are you trying to optimize? If you care about the startup time of
> > your interactive shell, 12 ms vs 6.7 ms doesn't make a difference.
>
> It is not for interactive use of zsh/bash. I am making scripts using
> shells. 12 vs 6.7 ms that is 1x or 50% difference depending on which
> way you consider the ratio, which is a quite significant difference.

Perhaps you can change your code to spawn fewer zsh processes?

What does your code look like? I've seen plenty of code that spends
most of its CPU time on forking but I don't recall seeing anything
that calls `zsh -dfc` or the like in a tight loop.

Roman.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  2019-09-06  9:35                   ` Roman Perepelitsa
@ 2019-09-06 12:57                     ` Peng Yu
  2019-09-06 13:11                       ` Roman Perepelitsa
  0 siblings, 1 reply; 19+ messages in thread
From: Peng Yu @ 2019-09-06 12:57 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Sebastian Gniazdowski, julien.nicoulaud, zsh-users

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

>
>
> Perhaps you can change your code to spawn fewer zsh processes?


I am doing so. But because zsh is much slower than bash, I will not use zsh
for my scripts at all. Only if it is faster than bash, I may consider using
it. I think this is one aspect that zsh developers may consider to optimize.

What does your code look like? I've seen plenty of code that spends
> most of its CPU time on forking but I don't recall seeing anything
> that calls `zsh -dfc` or the like in a tight loop.


I just use shebang to call a specific shell for a whole script.

>
> --
Regards,
Peng

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  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
  0 siblings, 2 replies; 19+ messages in thread
From: Roman Perepelitsa @ 2019-09-06 13:11 UTC (permalink / raw)
  To: Peng Yu; +Cc: Sebastian Gniazdowski, julien.nicoulaud, zsh-users

On Fri, Sep 6, 2019 at 2:57 PM Peng Yu <pengyu.ut@gmail.com> wrote:
>>
>>
>> Perhaps you can change your code to spawn fewer zsh processes?
>
>
> But because zsh is much slower than bash...

This isn't a fair summary of your benchmark. It would be more accurate
to say that zsh on some systems may take up to twice as long as bash
to execute an empty script.

> Only if it is faster than bash, I may consider using it.

Could you share some details of your environment in which the overhead
of 6.7 ms per script is OK but 12 ms is not?

When running a script interactively, this difference shouldn't matter.
12 ms is practically zero as far as human perception is concerned.
When running lots and lots of scripts in a tight loop, then it's
usually better to change your code to avoid spawning so many shell
processes. In zsh autoloading functions is often a good solution, but
the particular code changes will depend on what your code looks like
so that it results in so many shell processes.

Roman.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  2019-09-06 13:11                       ` Roman Perepelitsa
@ 2019-09-06 13:19                         ` Sebastian Gniazdowski
  2019-09-06 13:44                         ` Peng Yu
  1 sibling, 0 replies; 19+ messages in thread
From: Sebastian Gniazdowski @ 2019-09-06 13:19 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Peng Yu, julien.nicoulaud, zsh-users

On Fri, 6 Sep 2019 at 15:11, Roman Perepelitsa
<roman.perepelitsa@gmail.com> wrote:
> > But because zsh is much slower than bash...
>
> This isn't a fair summary of your benchmark. It would be more accurate
> to say that zsh on some systems may take up to twice as long as bash
> to execute an empty script.

Even this is too strong said. I would say: "zsh startups 5-7 ms longer
than bash".

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  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
  1 sibling, 1 reply; 19+ messages in thread
From: Peng Yu @ 2019-09-06 13:44 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Sebastian Gniazdowski, julien.nicoulaud, zsh-users

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

> > But because zsh is much slower than bash...
>
> This isn't a fair summary of your benchmark. It would be more accurate
> to say that zsh on some systems may take up to twice as long as bash
> to execute an empty script.


The slow startup is sufficient to deter me from using it as bash can
satisfy most of my usage. Although zsh has certain features that bash has,
I don’t want to trade-off the 2x startup time difference for those features.

I only care about the Unix variants but not Windows. My test is on Mac via
homebrew installations. I don’t think that there will be too much
difference in Linux. But I don’t have a native Linux machine to test.
Whoever has access to a native Linux machine may post the runtime here for
comparison of different OSes.

> Only if it is faster than bash, I may consider using it.
>
> Could you share some details of your environment in which the overhead
> of 6.7 ms per script is OK but 12 ms is not?
>
> When running a script interactively, this difference shouldn't matter.


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. 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.
-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: slow startup of zsh (1x slower than bash)
  2019-09-06 13:44                         ` Peng Yu
@ 2019-09-06 14:10                           ` Roman Perepelitsa
  0 siblings, 0 replies; 19+ messages in thread
From: Roman Perepelitsa @ 2019-09-06 14:10 UTC (permalink / raw)
  To: Peng Yu; +Cc: Sebastian Gniazdowski, julien.nicoulaud, zsh-users

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.

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2019-09-06 14:11 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-03 16:27 slow startup of zsh (1x slower than bash) 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

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).