Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: ZSH performance regression in 5.8.1.2-test
- X-seq: zsh-workers 50102
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Jordan Patterson <jordanp@xxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: ZSH performance regression in 5.8.1.2-test
- Date: Tue, 26 Apr 2022 00:01:04 -0700
- Archived-at: <https://zsh.org/workers/50102>
- In-reply-to: <CAH+w=7Yz-usT3nbbOW8o-awgZ_EKYVDaM_VVhyKYwaiOdxRzzw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAHDOzW6wE2aP6-MMrBNAUYttzQwi2VC_OY7tJDwkQwrtp47zEQ@mail.gmail.com> <CAH+w=7YwV=Cu1N7dSb417R1Q0vAMu6R6hAryXqE4RBkmU_w5gA@mail.gmail.com> <20220425192036.p6awbyro2a2lp7bq@chazelas.org> <CAH+w=7Yz-usT3nbbOW8o-awgZ_EKYVDaM_VVhyKYwaiOdxRzzw@mail.gmail.com>
On Mon, Apr 25, 2022 at 2:27 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> 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?
Try this?
diff --git a/Src/input.c b/Src/input.c
index c59232681..f904427a0 100644
--- a/Src/input.c
+++ b/Src/input.c
@@ -217,12 +217,36 @@ shinbufrestore(void)
static int
shingetchar(void)
{
- int nread;
+ int nread, rsize = 1;
if (shinbufptr < shinbufendptr)
return STOUC(*shinbufptr++);
-
+#ifdef HAVE_FSTAT
+ else {
+ struct stat st;
+ if (fstat(SHIN, &st) == 0 && !S_ISFIFO(st.st_mode))
+ rsize = SHINBUFSIZE;
+ }
+#endif
shinbufreset();
+ if (rsize > 1) {
+ do {
+ errno = 0;
+ nread = read(SHIN, shinbuffer, rsize);
+ } while (nread < 0 && errno == EINTR);
+ if (nread <= 0)
+ return -1;
+ if (isset(SHINSTDIN) &&
+ (shinbufendptr = memchr(shinbuffer, '\n', nread))) {
+ shinbufendptr++;
+ rsize = (shinbufendptr - shinbuffer);
+ if (nread > rsize &&
+ lseek(SHIN, -(nread - rsize), SEEK_CUR) < 0)
+ zerr("lseek(%d, %d): %e", SHIN, -(nread - rsize), errno);
+ } else
+ shinbufendptr = shinbuffer + nread;
+ return STOUC(*shinbufptr++);
+ }
for (;;) {
errno = 0;
nread = read(SHIN, shinbufendptr, 1);
Messages sorted by:
Reverse Date,
Date,
Thread,
Author