zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Clean but not very effective optimization (lex.c / dupstring_wlen)
@ 2018-10-16 22:08 Sebastian Gniazdowski
  2018-10-16 22:24 ` Sebastian Gniazdowski
  0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Gniazdowski @ 2018-10-16 22:08 UTC (permalink / raw)
  To: Zsh hackers list

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

Hello,
dupstring_wlen (i.e. with-len) is ready to use, so this patch is just
4 changes dupstring(s) -> dupstring_wlen(s, l). Each of those
dupstrings has a nice strlen() invocation already there in lex.c, a
few lines above.

Callgrind doesn't report any real change in number of instructions of
strlen() call and a test that repeatedly invokes (z) flag on a 32-line
buffer 150 times reports 24 ms for both unoptimized and optimized
version.

However performance test of F-Sy-Highlighting reports rather stable 40
ms gain – out of ~3000 ms, so not much.

In general simplicity of this patch made me send it.

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

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

diff --git a/Src/lex.c b/Src/lex.c
index 44ad880..fa29da3 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1626,7 +1626,7 @@ parsestrnoerr(char **s)
 
     zcontext_save();
     untokenize(*s);
-    inpush(dupstring(*s), 0, NULL);
+    inpush(dupstring_wlen(*s, l), 0, NULL);
     strinbeg(0);
     lexbuf.len = 0;
     lexbuf.ptr = tokstr = *s;
@@ -1658,7 +1658,7 @@ parse_subscript(char *s, int sub, int endchar)
     if (!*s || *s == endchar)
 	return 0;
     zcontext_save();
-    untokenize(t = dupstring(s));
+    untokenize(t = dupstring_wlen(s, l));
     inpush(t, 0, NULL);
     strinbeg(0);
     /*
@@ -1674,7 +1674,7 @@ parse_subscript(char *s, int sub, int endchar)
      * length preservation.
      */
     lexbuf.len = 0;
-    lexbuf.ptr = tokstr = dupstring(s);
+    lexbuf.ptr = tokstr = dupstring_wlen(s, l);
     lexbuf.siz = l + 1;
     err = dquote_parse(endchar, sub);
     toklen = (int)(lexbuf.ptr - tokstr);
@@ -1713,7 +1713,7 @@ parse_subst_string(char *s)
 	return 0;
     zcontext_save();
     untokenize(s);
-    inpush(dupstring(s), 0, NULL);
+    inpush(dupstring_wlen(s, l), 0, NULL);
     strinbeg(0);
     lexbuf.len = 0;
     lexbuf.ptr = tokstr = s;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Clean but not very effective optimization (lex.c / dupstring_wlen)
  2018-10-16 22:08 [PATCH] Clean but not very effective optimization (lex.c / dupstring_wlen) Sebastian Gniazdowski
@ 2018-10-16 22:24 ` Sebastian Gniazdowski
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Gniazdowski @ 2018-10-16 22:24 UTC (permalink / raw)
  To: Zsh hackers list

PS. I've run the F-Sy-H test via callgrind, twice, and in both runs
there is a drop in total instruction count, of 12.3 mln or 13 mln, out
of the total instruction count being 7.3 bilion. The lesser count is
of course for the optimized Zsh.
On Wed, 17 Oct 2018 at 00:08, Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> Hello,
> dupstring_wlen (i.e. with-len) is ready to use, so this patch is just
> 4 changes dupstring(s) -> dupstring_wlen(s, l). Each of those
> dupstrings has a nice strlen() invocation already there in lex.c, a
> few lines above.
>
> Callgrind doesn't report any real change in number of instructions of
> strlen() call and a test that repeatedly invokes (z) flag on a 32-line
> buffer 150 times reports 24 ms for both unoptimized and optimized
> version.
>
> However performance test of F-Sy-Highlighting reports rather stable 40
> ms gain – out of ~3000 ms, so not much.
>
> In general simplicity of this patch made me send it.
>
> --
> Sebastian Gniazdowski
> News: https://twitter.com/ZdharmaI
> IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
> Blog: http://zdharma.org



-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-16 22:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-16 22:08 [PATCH] Clean but not very effective optimization (lex.c / dupstring_wlen) Sebastian Gniazdowski
2018-10-16 22:24 ` Sebastian Gniazdowski

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).