Subject: Re: [BUG] Long line makes pattern matching (by //) hog Zsh
From: Sebastian Gniazdowski <[email-masked]>
To: Bart Schaefer <[email-masked]>
Cc: Zsh hackers list <[email-masked]>
Date: Sun, 5 Jun 2016 21:47:23 +0200
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On 5 June 2016 at 21:10, Bart Schaefer <[email-masked]> wrote:
> It's in the block in pattern.c:patchmatch() that begins with the
> comment:
>
>                 /*
>                  * Lookahead to avoid useless matches. This is not possible
>                  * with approximation.
>                  */
>
> Specifically, in the "if (no >= min) for (;;) ..." loop, at each charater
> in the input string patmatch() is called recursively to look at the rest
> of the string, which again enters this same loop because the next thing
> is also a one-or-more expression, which calls recursively and again
> enters the loop because the thing after that is a zero-or-more.
>
> It consumes a LOT of memory while doing this, even if I add a hack to
> prevent it from recursively re-entering lookahead (or to skip the
> lookahead entirely).

Too bad the input isn't even that large, ~2850 characters. And that
the pattern even with first segment removed – ([^0-9/\\\\
]##[^/\\\\]#(#e)) – i.e. two 0/1-or-more segments, is also slow,
although doesn't hog Zsh. Maybe your changes would make a difference
for that input size, and for first segment removed, i.e. two # or ##
blocks? I had simplified highlighting in my tool and should be fine
now, but maybe in future I could restore the more sophisticated
pattern.

Best regards,
Sebastian Gniazdowski