Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham
	autolearn_force=no version=3.4.1
Date: Sun, 14 Feb 2016 14:34:41 +0000
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Sebastian Gniazdowski <sgniazdowski@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Slow highlighting (Re: "drop-in replacement" and
 transpose-words-match)
Message-ID: <20160214143441.GB11737@tarsus.local2>
References: <CAKc7PVDhxbVgmV7WcGgyDzMmWSjwQ=7=LExXTwr7YvPzPpn2RA@mail.gmail.com>
 <160118223126.ZM28565@torch.brasslantern.com>
 <CAKc7PVB-X+DYVEHRqSoOiDAjNeTsVyz=EN72FHQuF=AnRmh65A@mail.gmail.com>
 <160119195608.ZM31931@torch.brasslantern.com>
 <20160123235303.GE20278@tarsus.local2>
 <160123222057.ZM16192@torch.brasslantern.com>
 <CAKc7PVCJFXCt+EVkYw3B7NDAUvdphgUuX6yjbt8mQYbv1Mx01w@mail.gmail.com>
 <160210101846.ZM2333@torch.brasslantern.com>
 <CAKc7PVAvJrGbzHrO8zwK_BxLdXH5knQNkiNrb0cE2h4Rh9A_Kg@mail.gmail.com>
 <CAKc7PVDDUDBdu0y-KmYXqwzqY8rPeeBQ9Fhi1RFZ5aXO6Wmt5g@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <CAKc7PVDDUDBdu0y-KmYXqwzqY8rPeeBQ9Fhi1RFZ5aXO6Wmt5g@mail.gmail.com>
User-Agent: Mutt/1.5.23 (2014-03-12)
X-Seq: zsh-workers 37967

Sebastian Gniazdowski wrote on Thu, Feb 11, 2016 at 17:11:57 +0100:
> On 11 February 2016 at 11:43, Sebastian Gniazdowski
> <sgniazdowski@gmail.com> wrote:
> > That said, zsyh could be somewhat optimized if the ":howmany" syntax
> > would be utilized.
> 
> Could came up with this:
> ./parse.zsh "zplugin.zsh" > out1.txt 128,78s user 8,61s system 99% cpu
> 2:17,85 total
> ./parse.zsh "zplugin.zsh" > out2.txt 74,34s user 8,38s system 99% cpu
> 1:23,12 total
> 
> https://github.com/zsh-users/zsh-syntax-highlighting/pull/272
> 

Thanks!  Merged, will be in 0.5.0.

However, I think avoiding the strlen() isn't the main benefit here:
I suspect the expression $buf[start_pos+1,-1], which is evaluated in
every iteration of the loop, might have triggered an O(N²) allocations
pattern, even before considering the implicit strlen for the -1 (or the
explicit strlen in the "else" branch).

The next step might be to see whether the two remaining instances of
that expression (one in the 'if' branch and one in the 'else' branch)
can also be simplified: for example, by precomputing the indices of all
newlines, semicolons, and starts-of-words (places where the regexp /\</
matches) in $buf.

Many thanks for your investigation!  I'd also like to thank Bart for his
help (some of which was offlist).

Daniel

