From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 9d6595da for ; Fri, 7 Feb 2020 11:31:16 +0000 (UTC) Received: (qmail 15181 invoked by alias); 7 Feb 2020 11:31:11 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45395 Received: (qmail 22527 invoked by uid 1010); 7 Feb 2020 11:31:11 -0000 X-Qmail-Scanner-Diagnostics: from mail-io1-f67.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.1/25713. spamassassin: 3.4.2. Clear:RC:0(209.85.166.67):SA:0(-2.0/5.0):. Processed in 4.057645 secs); 07 Feb 2020 11:31:11 -0000 X-Envelope-From: mikachu@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.166.67 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=gV183whzIN8hziUo59O6+SgGf1vxkazcy1yGhkmpRv8=; b=azlTkyUDWABBSn7azmVBc8p1IOafs5qzSj6d2D5tIjegbQJwwZoYxj+fZpA3Y/oJM8 sYRhCdU9bv+WgIgM2FWvnncPaTCwAPqjKLokh6cblL7aB5N8b+9avG9UusGRS4huuAZx 1r5VT7gR8gxJXaQy6DusHMdZ3g8bcjtuCaLWcX9fmGlMyBGtp5++uyX25pNRuXrbOZP8 wtfcKslx0U4HltLzWkuAI7iRIgTCnJaXn638Du8USQmKshtst1F7Tx/052/SGzBIHF3c gyoyTeUK79rIkqxjMgRxa3Ps1IvNf8EZVfnQw4ZpcwaqcBQyCAtsajsoA017EYo3cu5i B97g== X-Gm-Message-State: APjAAAWzMeFXp/l1HxlqHxvk5m3dpk1akRp3EmZbmZ4qa5dhzoTq6oBe caetk64QvSCrBMnk8Ioomes8FvoRlEhWcrw5ysQNLA== X-Google-Smtp-Source: APXvYqx40kPgHydnjq/NW0+UqTPzm5paFAfR9156B7fmIQcrnBs+MlVMr5hvVAFPr11zFGx/by1XlqzSkVFKl2gpHtQ= X-Received: by 2002:a6b:5b19:: with SMTP id v25mr2762529ioh.13.1581075034594; Fri, 07 Feb 2020 03:30:34 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: From: Mikael Magnusson Date: Fri, 7 Feb 2020 12:30:33 +0100 Message-ID: Subject: Re: [PATCH] readhistfile: avoid thousands of lseek(2) syscalls via ftell() To: Michael Stapelberg Cc: zsh-workers@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On 2/7/20, Michael Stapelberg wrote: > [please cc me in replies, as I=E2=80=99m not subscribed to this list] > > Before this change, zsh startup time was dominated by lseek(2) system cal= ls > 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 > [=E2=80=A6] > > 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 +=3D strlen(buf + start); > int len =3D start + strlen(buf + start); int len =3D strlen(buf + start); *readbytes +=3D len; len +=3D 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?). --=20 Mikael Magnusson