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

Re: ZSH performance regression in 5.8.1.2-test



On Mon, Apr 25, 2022 at 12:20 PM Stephane Chazelas
<stephane@xxxxxxxxxxxx> wrote:
>
> 2022-04-25 11:56:59 -0700, Bart Schaefer:
> > On Mon, Apr 25, 2022 at 11:26 AM Jordan Patterson <jordanp@xxxxxxxxx> wrote:
> > >
> > > This recent fix has led to a performance regression in zsh: 49792:
> > > Non-interative shell input is line buffered.

Jumping back to this for a moment:
> > > Summary
> > >  'prefix/5.8.1/bin/zsh -i -c exit' ran
> > >    1.16 ± 0.06 times faster than 'prefix/5.8/bin/zsh -i -c exit'
> > >    9.22 ± 0.27 times faster than 'prefix/5.8.1.2-test/bin/zsh -i -c exit'

I hadn't parsed closely before that 5.8.1 is faster than 5.8.  That
means avoiding stdio is faster if we don't have to do line-buffering.

> > Is there a way we can detect the case where we need to line-buffer and
> > avoid it otherwise?
>
> Sorry if I'm beside the point as I don't know the context here,

The context is shell command input, that is, any of
1) loading init files
2) source or . command
3) zsh < file
4) command | zsh

Have I missed any?

The bug from https://bugs.gentoo.org/839900 crops up in a special case
of 3 or 4 when the input runs a sub-command that itself wants to read
from stdin.  In that case the shell is supposed to have stopped
reading at a newline, leaving the rest of the original input available
to be consumed by the sub-command.

>[...] some other shells, when the input is seekable do read by
> blocks (instead of one byte at a time), and seek back to just
> after the newline when they've read too much.

Theoretically we can block-read with impunity in cases 1 and 2 (anyone
disagree?).  Testing for seek-ability would allow doing the "read too
much and back up" trick in case 3.  I don't immediately see any way to
avoid reading one byte at a time in case 4, does anyone have a
suggestion?

It does not appear from some quick tests that lseek(SHIN, 0, SEEK_CUR)
is guaranteed to succeed in case 3 nor to fail with ESPIPE in case 4.
How to distinguish them?




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