Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] readhistfile: avoid thousands of lseek(2) syscalls via ftell()
- X-seq: zsh-workers 45395
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Michael Stapelberg <michael+zsh@xxxxxxxxxxxxx>
- Subject: Re: [PATCH] readhistfile: avoid thousands of lseek(2) syscalls via ftell()
- Date: Fri, 7 Feb 2020 12:30:33 +0100
- Cc: zsh-workers@xxxxxxx
- In-reply-to: <CANnVG6=LfCpg7SQyiGreLzDLKi2Za0pUDR3cCzV6T6cquUr1GA@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CANnVG6=LfCpg7SQyiGreLzDLKi2Za0pUDR3cCzV6T6cquUr1GA@mail.gmail.com>
On 2/7/20, Michael Stapelberg <michael+zsh@xxxxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author