From: "Paulo César Pereira de Andrade" <paulo.cesar.pereira.de.andrade@gmail.com>
To: zsh-users@zsh.org
Subject: There is a serious inefficiency in the way zsh handles wildcards
Date: Mon, 8 Sep 2014 10:27:48 -0300 [thread overview]
Message-ID: <CAHAq8pF=hB4sfx+Fe6nfnbJ8W7E9r9e_mHytBdu=Oy_6CWukJA@mail.gmail.com> (raw)
Hello,
I had a bug report described as @subject. The test case was described as:
---%<---
$ time zsh -c "ls /tmp/*****.*****"
real 0m0.006s
user 0m0.004s
sys 0m0.002s
$ time zsh -c "ls /tmp/******.******"
real 0m0.032s
user 0m0.031s
sys 0m0.001s
$ time zsh -c "ls /tmp/*******.*******"
real 0m0.127s
user 0m0.125s
sys 0m0.003s
$ time zsh -c "ls /tmp/********.********"
real 0m0.485s
user 0m0.484s
sys 0m0.002s
$ time zsh -c "ls /tmp/**********.**********"
real 0m5.933s
user 0m5.937s
sys 0m0.002s
---%<---
I did look a bit in zsh sources, and wrote this patch, that should not interfere
on the special handling of **/ and ***/, and just avoid the very deep recursions
that consume a huge amount of cpu, and apparently yield nothing.
---%<---
diff -up zsh-5.0.2/Src/pattern.c.orig zsh-5.0.2/Src/pattern.c
--- zsh-5.0.2/Src/pattern.c.orig 2014-09-03 12:21:44.673792750 -0300
+++ zsh-5.0.2/Src/pattern.c 2014-09-03 12:22:28.069303587 -0300
@@ -2911,6 +2911,10 @@ patmatch(Upat prog)
break;
case P_STAR:
/* Handle specially for speed, although really P_ONEHASH+P_ANY */
+ while (P_OP(next) == P_STAR) {
+ scan = next;
+ next = PATNEXT(scan);
+ }
case P_ONEHASH:
case P_TWOHASH:
/*
---%<---
Do you believe this patch is OK?
The user reports those patterns are generated by one of their scripts.
Thanks,
Paulo
next reply other threads:[~2014-09-08 13:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-08 13:27 Paulo César Pereira de Andrade [this message]
2014-09-08 14:01 ` Peter Stephenson
2014-09-11 13:54 ` Paulo César Pereira de Andrade
2014-09-11 14:02 ` Peter Stephenson
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='CAHAq8pF=hB4sfx+Fe6nfnbJ8W7E9r9e_mHytBdu=Oy_6CWukJA@mail.gmail.com' \
--to=paulo.cesar.pereira.de.andrade@gmail.com \
--cc=zsh-users@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).