From: Bart Schaefer <schaefer@brasslantern.com>
To: Jordan Patterson <jordanp@gmail.com>,
Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: ZSH performance regression in 5.8.1.2-test
Date: Tue, 26 Apr 2022 00:01:04 -0700 [thread overview]
Message-ID: <CAH+w=7bb+3T5MabhmCS9BwC7XmTxmydxQ5GLy7R7+6f6B7-=EA@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7Yz-usT3nbbOW8o-awgZ_EKYVDaM_VVhyKYwaiOdxRzzw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 391 bytes --]
On Mon, Apr 25, 2022 at 2:27 PM Bart Schaefer <schaefer@brasslantern.com> 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?
[-- Attachment #2: sysread.txt --]
[-- Type: text/plain, Size: 1100 bytes --]
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);
next prev parent reply other threads:[~2022-04-26 7:01 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-25 18:16 Jordan Patterson
2022-04-25 18:56 ` Bart Schaefer
2022-04-25 19:20 ` Stephane Chazelas
2022-04-25 21:27 ` Bart Schaefer
2022-04-26 7:01 ` Bart Schaefer [this message]
2022-04-26 8:31 ` Peter Stephenson
2022-04-27 0:33 ` Bart Schaefer
2022-04-27 14:11 ` Stephane Chazelas
2022-04-27 15:02 ` Bart Schaefer
2022-04-27 15:07 ` Peter Stephenson
2022-04-27 15:17 ` Bart Schaefer
2022-04-26 14:31 ` Jun. T
2022-04-26 15:15 ` Peter Stephenson
2022-04-27 0:55 ` Bart Schaefer
2022-04-27 9:16 ` Jun T
2022-04-27 0:38 ` Bart Schaefer
2022-04-27 9:34 ` Peter Stephenson
2022-04-27 10:28 ` Jun T
2022-04-27 12:42 ` Jun T
2022-04-27 13:58 ` Jun T
2022-04-27 15:25 ` Bart Schaefer
2022-04-27 16:18 ` Jun. T
2022-04-27 19:54 ` Jordan Patterson
2022-04-28 9:53 ` Jun T
2022-04-28 14:56 ` Bart Schaefer
2022-04-28 18:51 ` Jun. T
2022-04-29 0:28 ` Bart Schaefer
2022-04-29 2:25 ` Jun. T
2022-04-26 1:08 ` Bart Schaefer
2022-04-26 3:03 ` Jordan Patterson
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='CAH+w=7bb+3T5MabhmCS9BwC7XmTxmydxQ5GLy7R7+6f6B7-=EA@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=jordanp@gmail.com \
--cc=zsh-workers@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).