zsh-workers
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] ztrsub() execution time / 2
Date: Wed, 17 Oct 2018 06:29:08 +0200	[thread overview]
Message-ID: <CAKc7PVCMrcNChf2macaVBohMVRq=BcJy6QjHM4w22i9tJX1pXw@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 893 bytes --]

Hello,
this optimization is a drop of callgrind instruction count by 43 mln
for ztrsub() – it had 89 mln instructions normally, now it has 46 mln:

ztrsub() callgrind I-count:
1> (89873326 - 46452836) / 1000000.0
43,4205

total callgrind I-count
2> (7906279976 - 7858975498) / 1000000.0
47,3045

 89,873,326  ztrsub [/usr/local/bin/zsh-5.6.2-dev-1-2noopt]
vs
 46,452,836  ztrsub [/usr/local/bin/zsh-5.6.2-dev-1-2yesopt]

Ran this callgrind probe twice to confirm. That said, `zsh -i -c exit'
nor a performance test script show any gain. I wonder why.. But
callgrind doesn't lie, and looking at the code one can understand why
I-count dropped by factor of 2. The patch has many context lines to
see whole function.
-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

[-- Attachment #2: ztrsub_opt.diff.txt --]
[-- Type: text/plain, Size: 633 bytes --]

diff --git a/Src/utils.c b/Src/utils.c
index 914e30c..1eb8c71 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -5058,23 +5058,23 @@ ztrlenend(char const *s, char const *eptr)
 #endif /* MULTIBYTE_SUPPORT */
 
 /* Subtract two pointers in a metafied string. */
 
 /**/
 mod_export int
 ztrsub(char const *t, char const *s)
 {
     int l = t - s;
 
     while (s != t) {
-	if (*s++ == Meta) {
+	if (*s++ == Meta || (s != t && *s++ == Meta)) {
 #ifdef DEBUG
 	    if (! *s || s == t)
 		fprintf(stderr, "BUG: substring ends in the middle of a metachar in ztrsub()\n");
 	    else
 #endif
 	    s++;
 	    l--;
 	}
     }
     return l;
 }

             reply	other threads:[~2018-10-17  4:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-17  4:29 Sebastian Gniazdowski [this message]
2018-10-17 14:25 ` Daniel Shahaf
2018-10-17 19:02   ` Sebastian Gniazdowski
2018-10-17 19:34     ` Daniel Shahaf

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='CAKc7PVCMrcNChf2macaVBohMVRq=BcJy6QjHM4w22i9tJX1pXw@mail.gmail.com' \
    --to=sgniazdowski@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).