zsh-workers
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: zsh-workers@zsh.org
Subject: Re: Substitution ${...///} slows down when certain UTF character occurs
Date: Thu, 1 Oct 2015 15:45:17 +0200	[thread overview]
Message-ID: <CAKc7PVDYdek1hOb9xp1EQshjUzT5zsrBsKWQOiNtES_8OQoV3w@mail.gmail.com> (raw)
In-Reply-To: <150927091121.ZM25721@torch.brasslantern.com>

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

On 27 September 2015 at 18:11, Bart Schaefer
> It'll get worse if there are partial matches, e.g., if you had 30000
> repetitions of "wfei" and scanned for "wfeiwj" there'd be a whole lot
> of backtracking.  There are no "w" anywhere in your sample $str so
> each of the comparisons is only one equality test.

It's still instant fast for 30k of wfei (attached is the script). I
also tried generating a [wfeiwj]-only string, and it's also fast:

cat /dev/urandom | env LC_CTYPE=C tr -cd 'wfeiwj' | head -c 120000 > input

Gave it one more try with
"wfeiwjwoiejfowiejfowijefoiwjefoiwjefoijwoeifjwoiejf" (30k of it, and
was searching for it) and it becomes slower (times 0.15s instead of
0.012s) but is still instant fast.

>
> Still I think the biggest issue is that unmetafication happening too
> low down.  Since pattry*() is being called repeatedly with the same two
> first arguments (prog and string) it might be possible to cache the
> unmetafied string after the first call.

I wonder why it depends on Zsh version and/or environment (OS, etc.).
This doesn't seem related to unmetafication, unless it was changed
after 5.0.2.

Best regards,
Sebastian Gniazdowski

[-- Attachment #2: test-script.zsh --]
[-- Type: application/octet-stream, Size: 507 bytes --]

#!/usr/local/bin/zsh

emulate -LR zsh

str=""

i=30000
while (( i -- )); do
    str[1,0]="wfei"
done
#echo "$str" > input


#char="–"
char="¥"
#char="Ń"
#char="Ł"
#char="Ǎ"
#char="Ǟ"

str[60]=$char
time ( out_array=( "${str//(#bi)wfeiwj/a}" ) )
str[60]="a"

str[10000]=$char
time ( out_array=( "${str//(#bi)wfeiwj/a}" ) )
str[10000]="a"

str[50000]=$char
time ( out_array=( "${str//(#bi)wfeiwj/a}" ) )
str[50000]="a"

str[100000]=$char
time ( out_array=( "${str//(#bi)wfeiwj/a}" ) )
str[100000]="a"


      parent reply	other threads:[~2015-10-01 13:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-26 12:19 Sebastian Gniazdowski
2015-09-26 20:44 ` Bart Schaefer
2015-09-27  8:13   ` Sebastian Gniazdowski
2015-09-27 16:11     ` Bart Schaefer
2015-09-28  8:51       ` Peter Stephenson
2015-09-28 11:30         ` Peter Stephenson
2015-09-28 19:23         ` Peter Stephenson
2015-09-29  8:44           ` Peter Stephenson
2015-09-29 18:37             ` Peter Stephenson
2015-09-29 19:23               ` Bart Schaefer
2015-09-30  8:59                 ` Peter Stephenson
2015-09-30 14:04                   ` Peter Stephenson
2015-09-30 21:19                     ` Bart Schaefer
2015-10-01  8:41                       ` Peter Stephenson
2015-10-01 14:28                         ` Heap corruption [the thread formerly known as substitution] Peter Stephenson
2015-10-01 15:07                           ` Bart Schaefer
2015-10-01 15:13                           ` Peter Stephenson
2015-10-03 18:59                             ` Peter Stephenson
2015-10-01 13:45       ` Sebastian Gniazdowski [this message]

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=CAKc7PVDYdek1hOb9xp1EQshjUzT5zsrBsKWQOiNtES_8OQoV3w@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).