From: Mikael Magnusson <mikachu@gmail.com>
To: Michael Stapelberg <michael+zsh@stapelberg.ch>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH] readhistfile: avoid thousands of lseek(2) syscalls via ftell()
Date: Fri, 7 Feb 2020 12:30:33 +0100 [thread overview]
Message-ID: <CAHYJk3T+4VwToio67q0UeQ4vmcTJopvZiwYXP18+usfyY+LYoA@mail.gmail.com> (raw)
In-Reply-To: <CANnVG6=LfCpg7SQyiGreLzDLKi2Za0pUDR3cCzV6T6cquUr1GA@mail.gmail.com>
On 2/7/20, Michael Stapelberg <michael+zsh@stapelberg.ch> wrote:
> [please cc me in replies, as I’m not subscribed to this list]
>
> Before this change, zsh startup time was dominated by lseek(2) system calls
> on
> the history file, as shown by strace -c:
>
> time seconds usecs/call calls errors syscall
> ------ ----------- ----------- --------- --------- ----------------
> 97,35 1,112890 1 697153 1 lseek
> 0,99 0,011314 2 5277 read
> […]
>
> This change keeps track of read bytes and the position within the file,
> removing
> all of these system calls.
>
> I verified correctness of the change by comparing fpos with ftell(in) in
> every
> loop iteration.
> + *readbytes += strlen(buf + start);
> int len = start + strlen(buf + start);
int len = strlen(buf + start);
*readbytes += len;
len += start;
Even if you're convinced the compiler will optimize the double strlen
calls, the declaration has to come before code (I don't think we
require new enough C to not require this yet?).
--
Mikael Magnusson
next prev parent reply other threads:[~2020-02-07 11:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-07 7:47 Michael Stapelberg
2020-02-07 11:30 ` Mikael Magnusson [this message]
2020-02-07 11:33 ` Michael Stapelberg
2021-04-10 0:54 ` Oliver Kiddle
2021-04-10 17:31 ` Bart Schaefer
2020-02-08 5:54 ` Bart Schaefer
2020-02-08 7:47 ` Michael Stapelberg
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=CAHYJk3T+4VwToio67q0UeQ4vmcTJopvZiwYXP18+usfyY+LYoA@mail.gmail.com \
--to=mikachu@gmail.com \
--cc=michael+zsh@stapelberg.ch \
--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).