zsh-workers
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Slow highlighting (Re: "drop-in replacement" and transpose-words-match)
Date: Thu, 11 Feb 2016 11:43:50 +0100	[thread overview]
Message-ID: <CAKc7PVAvJrGbzHrO8zwK_BxLdXH5knQNkiNrb0cE2h4Rh9A_Kg@mail.gmail.com> (raw)
In-Reply-To: <160210101846.ZM2333@torch.brasslantern.com>

Hello,

a=""; a=${(r:100000::_:)a}; zshstyle() { repeat 100; do
b=${a[-5000,-1]}; done }; shstyle() { repeat 100; do b=${a:
-5000:5000}; done }; time ( zshstyle ); time ( shstyle )

( zshstyle; )  0,66s user 0,01s system 99% cpu 0,673 total
( shstyle; )  0,40s user 0,00s system 99% cpu 0,402 total

The point of this tangent example is: every indexing works by
iterating over buffer and counting characters. By using ":5000" one
pass of finding where an index points to is skipped, as it says "5000
characters from now on". Index -1 iterates from the beginning again to
find end of string.

Here Zsyh indexes buffer, uses -1 and also (i):

    if [[ $arg == ';' ]] ; then
      local needle=$'[;\n]'
      integer offset=${${buf[start_pos+1,-1]}[(i)$needle]}
      (( start_pos += offset - 1 ))
      (( end_pos = start_pos + $#arg ))
    else
      ((start_pos+=${#buf[$start_pos+1,-1]}-${#${buf[$start_pos+1,-1]##([[:space:]]|\\[[:space:]])#}}))
      ((end_pos=$start_pos+${#arg}))
    fi

The longer the buffer the more time -1 consumes. Of course any
indexing is slow, not only -1, but this is nice emphasis of the issue.
The only solution is apparently making Zsh storing strings as real
arrays, of wint_t type.

As for the (i), as far as I remember from the time I worked on C
source, reverse indexing uses one additional "iterate counting
characters" block:

https://github.com/zsh-users/zsh/blob/master/Src/params.c#L1360-L1396

That said, zsyh could be somewhat optimized if the ":howmany" syntax
would be utilized.

Best regards,
Sebastian Gniazdowski


  parent reply	other threads:[~2016-02-11 10:44 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-12  7:32 "drop-in replacement" and transpose-words-match Bart Schaefer
2016-01-18  2:25 ` Daniel Shahaf
2016-01-18 16:29   ` Bart Schaefer
2016-01-18 17:04 ` Sebastian Gniazdowski
2016-01-19  6:31   ` Bart Schaefer
2016-01-19  8:28     ` Sebastian Gniazdowski
2016-01-20  3:56       ` Bart Schaefer
2016-01-23 23:53         ` Daniel Shahaf
2016-01-24  6:20           ` Slow highlighting (Re: "drop-in replacement" and transpose-words-match) Bart Schaefer
2016-01-26 22:50             ` Daniel Shahaf
2016-01-27  4:31               ` Bart Schaefer
2016-01-27  5:10                 ` Mikael Magnusson
2016-01-29  9:18                 ` Daniel Shahaf
2016-02-10 16:32             ` Sebastian Gniazdowski
2016-02-10 18:18               ` Bart Schaefer
2016-02-10 18:37                 ` Sebastian Gniazdowski
2016-02-11 10:43                 ` Sebastian Gniazdowski [this message]
2016-02-11 12:07                   ` Sebastian Gniazdowski
2016-02-14 14:34                     ` Daniel Shahaf
2016-02-11 16:11                   ` Sebastian Gniazdowski
2016-02-12  7:34                     ` Sebastian Gniazdowski
2016-02-12 10:05                     ` Bart Schaefer
2016-02-14 14:34                     ` Daniel Shahaf
2016-02-12  9:41                   ` Bart Schaefer
2016-05-06 13:15                     ` Sebastian Gniazdowski
2016-02-14 14:34                   ` Avoiding github link bitrot " Daniel Shahaf
2016-01-20  7:47       ` "drop-in replacement" and transpose-words-match 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=CAKc7PVAvJrGbzHrO8zwK_BxLdXH5knQNkiNrb0cE2h4Rh9A_Kg@mail.gmail.com \
    --to=sgniazdowski@gmail.com \
    --cc=schaefer@brasslantern.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).