* Progressively slow pattern match
@ 2006-05-17 19:33 Ralf Angeli
2006-05-17 19:37 ` David Kastrup
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Ralf Angeli @ 2006-05-17 19:33 UTC (permalink / raw)
In AUCTeX there is a regexp used with `looking-at' where pattern
matching seems to progressively get slower the longer a part of the
(possible) match gets. I reduced the regexp to a bare minimum for
testing and the code now looks something like this:
(looking-at "\\(%+\\)*foo")
The problem occurs if this is used against a line with only %
characters in it. The more of these characters there are the slower
it gets. I checked the time one call of `looking-at' takes with
(abs (- (float-time) (progn (looking-at "\\(%+\\)*foo") (float-time))))
and got the following results (in seconds):
%%%%%%%%%% 0.0006
%%%%%%%%%%%%%%% 0.0154
%%%%%%%%%%%%%%%%%%%% 0.5132
%%%%%%%%%%%%%%%%%%%%%%%%% 7.8058
The regexp is used with `looking-at' for checking if there are LaTeX
macros which have to be treated specially during paragraph movement.
As paragraph movement is used quite extensively when a region is to be
filled, users might get the notion that they are experiencing a hang
if they have such line for visually separating parts in the file.
Is this a deficiency in Emacs? Is there a way matching can be sped up
with this or maybe another, equivalent regexp?
--
Ralf
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Progressively slow pattern match
2006-05-17 19:33 Progressively slow pattern match Ralf Angeli
@ 2006-05-17 19:37 ` David Kastrup
2006-05-17 19:50 ` Kevin Rodgers
2006-05-17 19:50 ` Ralf Angeli
2006-05-17 19:53 ` Alan Mackenzie
2006-05-17 23:13 ` Richard Stallman
2 siblings, 2 replies; 10+ messages in thread
From: David Kastrup @ 2006-05-17 19:37 UTC (permalink / raw)
Cc: emacs-devel
Ralf Angeli <angeli@caeruleus.net> writes:
> In AUCTeX there is a regexp used with `looking-at' where pattern
> matching seems to progressively get slower the longer a part of the
> (possible) match gets. I reduced the regexp to a bare minimum for
> testing and the code now looks something like this:
>
> (looking-at "\\(%+\\)*foo")
>
> The problem occurs if this is used against a line with only %
> characters in it. The more of these characters there are the slower
> it gets. I checked the time one call of `looking-at' takes with
> (abs (- (float-time) (progn (looking-at "\\(%+\\)*foo") (float-time))))
> and got the following results (in seconds):
>
> %%%%%%%%%% 0.0006
> %%%%%%%%%%%%%%% 0.0154
> %%%%%%%%%%%%%%%%%%%% 0.5132
> %%%%%%%%%%%%%%%%%%%%%%%%% 7.8058
>
> The regexp is used with `looking-at' for checking if there are LaTeX
> macros which have to be treated specially during paragraph movement.
> As paragraph movement is used quite extensively when a region is to be
> filled, users might get the notion that they are experiencing a hang
> if they have such line for visually separating parts in the file.
>
> Is this a deficiency in Emacs? Is there a way matching can be sped up
> with this or maybe another, equivalent regexp?
Uh, "\\(%+\\)?foo" maybe?
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Progressively slow pattern match
2006-05-17 19:37 ` David Kastrup
@ 2006-05-17 19:50 ` Kevin Rodgers
2006-05-17 19:50 ` Ralf Angeli
1 sibling, 0 replies; 10+ messages in thread
From: Kevin Rodgers @ 2006-05-17 19:50 UTC (permalink / raw)
David Kastrup wrote:
> Ralf Angeli <angeli@caeruleus.net> writes:
>
>> In AUCTeX there is a regexp used with `looking-at' where pattern
>> matching seems to progressively get slower the longer a part of the
>> (possible) match gets. I reduced the regexp to a bare minimum for
>> testing and the code now looks something like this:
>>
>> (looking-at "\\(%+\\)*foo")
>>
>> The problem occurs if this is used against a line with only %
>> characters in it. The more of these characters there are the slower
>> it gets. I checked the time one call of `looking-at' takes with
>> (abs (- (float-time) (progn (looking-at "\\(%+\\)*foo") (float-time))))
>> and got the following results (in seconds):
>>
>> %%%%%%%%%% 0.0006
>> %%%%%%%%%%%%%%% 0.0154
>> %%%%%%%%%%%%%%%%%%%% 0.5132
>> %%%%%%%%%%%%%%%%%%%%%%%%% 7.8058
>>
>> The regexp is used with `looking-at' for checking if there are LaTeX
>> macros which have to be treated specially during paragraph movement.
>> As paragraph movement is used quite extensively when a region is to be
>> filled, users might get the notion that they are experiencing a hang
>> if they have such line for visually separating parts in the file.
>>
>> Is this a deficiency in Emacs? Is there a way matching can be sped up
>> with this or maybe another, equivalent regexp?
>
> Uh, "\\(%+\\)?foo" maybe?
Or even just "\\(%*\\)foo".
--
Kevin
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Progressively slow pattern match
2006-05-17 19:37 ` David Kastrup
2006-05-17 19:50 ` Kevin Rodgers
@ 2006-05-17 19:50 ` Ralf Angeli
2006-05-17 20:00 ` Alan Mackenzie
` (2 more replies)
1 sibling, 3 replies; 10+ messages in thread
From: Ralf Angeli @ 2006-05-17 19:50 UTC (permalink / raw)
Cc: emacs-devel
* David Kastrup (2006-05-17) writes:
> Ralf Angeli <angeli@caeruleus.net> writes:
>
>> (looking-at "\\(%+\\)*foo")
[...]
>> Is this a deficiency in Emacs? Is there a way matching can be sped up
>> with this or maybe another, equivalent regexp?
>
> Uh, "\\(%+\\)?foo" maybe?
The original regexp looks something like
"\\(%+[ \t]*\\)*foo"
in order to match stuff like
%% %% %% foo
--
Ralf
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Progressively slow pattern match
2006-05-17 19:33 Progressively slow pattern match Ralf Angeli
2006-05-17 19:37 ` David Kastrup
@ 2006-05-17 19:53 ` Alan Mackenzie
2006-05-17 23:13 ` Richard Stallman
2 siblings, 0 replies; 10+ messages in thread
From: Alan Mackenzie @ 2006-05-17 19:53 UTC (permalink / raw)
Cc: emacs-devel
'n Abend, Ralf!
On Wed, 17 May 2006, Ralf Angeli wrote:
>In AUCTeX there is a regexp used with `looking-at' where pattern
>matching seems to progressively get slower the longer a part of the
>(possible) match gets. I reduced the regexp to a bare minimum for
>testing and the code now looks something like this:
>(looking-at "\\(%+\\)*foo")
>The problem occurs if this is used against a line with only %
>characters in it. The more of these characters there are the slower
>it gets. I checked the time one call of `looking-at' takes with
>(abs (- (float-time) (progn (looking-at "\\(%+\\)*foo") (float-time))))
>and got the following results (in seconds):
>%%%%%%%%%% 0.0006
>%%%%%%%%%%%%%%% 0.0154
>%%%%%%%%%%%%%%%%%%%% 0.5132
>%%%%%%%%%%%%%%%%%%%%%%%%% 7.8058
>The regexp is used with `looking-at' for checking if there are LaTeX
>macros which have to be treated specially during paragraph movement.
>As paragraph movement is used quite extensively when a region is to be
>filled, users might get the notion that they are experiencing a hang
>if they have such line for visually separating parts in the file.
>Is this a deficiency in Emacs? Is there a way matching can be sped up
>with this or maybe another, equivalent regexp?
It's a bad regexp. It's got a sort of ambiguity, in that you've got both
a "+" and a "*" on the "%" you want to match. The number of ways %+* can
divide a row of n %s is the number of ordered partions of n[*]. The
Emacs regexp engine tries out ALL of these, I think. Each time it comes
to the non-% at the end, it goes back to try a different subdivision, to
see if that gives a longer match. Evidently, each % you add doubles the
time the regexp engine takes, approximately (though I suspect that for
your last timining, the jump was only 4%, not 5%).
And yes, I've done this too. :-( The solution is to write either %+ or
%*, but not both together.
[*] As in, 4 = 3 + 1
= 2 + 1 + 1
= 1 + 2 + 1
= 1 + 3
= 2 + 2
= 1 + 1 + 2
= 1 + 1 + 1 + 1
>Ralf
--
Alan.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Progressively slow pattern match
2006-05-17 19:50 ` Ralf Angeli
@ 2006-05-17 20:00 ` Alan Mackenzie
2006-05-17 21:13 ` Ralf Angeli
2006-05-17 20:04 ` David Kastrup
2006-05-17 20:21 ` Stuart D. Herring
2 siblings, 1 reply; 10+ messages in thread
From: Alan Mackenzie @ 2006-05-17 20:00 UTC (permalink / raw)
Cc: emacs-devel
On Wed, 17 May 2006, Ralf Angeli wrote:
>* David Kastrup (2006-05-17) writes:
>> Ralf Angeli <angeli@caeruleus.net> writes:
>>> (looking-at "\\(%+\\)*foo")
>[...]
>>> Is this a deficiency in Emacs? Is there a way matching can be sped up
>>> with this or maybe another, equivalent regexp?
>> Uh, "\\(%+\\)?foo" maybe?
>The original regexp looks something like
>"\\(%+[ \t]*\\)*foo"
>in order to match stuff like
>%% %% %% foo
Use "\\(%+[ \t]+\\)%*foo"
^
instead
>Ralf
--
Alan.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Progressively slow pattern match
2006-05-17 19:50 ` Ralf Angeli
2006-05-17 20:00 ` Alan Mackenzie
@ 2006-05-17 20:04 ` David Kastrup
2006-05-17 20:21 ` Stuart D. Herring
2 siblings, 0 replies; 10+ messages in thread
From: David Kastrup @ 2006-05-17 20:04 UTC (permalink / raw)
Cc: emacs-devel
Ralf Angeli <angeli@caeruleus.net> writes:
> * David Kastrup (2006-05-17) writes:
>
>> Ralf Angeli <angeli@caeruleus.net> writes:
>>
>>> (looking-at "\\(%+\\)*foo")
> [...]
>>> Is this a deficiency in Emacs? Is there a way matching can be sped up
>>> with this or maybe another, equivalent regexp?
>>
>> Uh, "\\(%+\\)?foo" maybe?
>
> The original regexp looks something like
> "\\(%+[ \t]*\\)*foo"
> in order to match stuff like
> %% %% %% foo
"\\(%[% \t]*\\)foo"
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Progressively slow pattern match
2006-05-17 19:50 ` Ralf Angeli
2006-05-17 20:00 ` Alan Mackenzie
2006-05-17 20:04 ` David Kastrup
@ 2006-05-17 20:21 ` Stuart D. Herring
2 siblings, 0 replies; 10+ messages in thread
From: Stuart D. Herring @ 2006-05-17 20:21 UTC (permalink / raw)
Cc: emacs-devel
> The original regexp looks something like
> "\\(%+[ \t]*\\)*foo"
> in order to match stuff like
> %% %% %% foo
Try "\\(%+\\(?:[ \t]+%+\\)*\\)"? I think that should avoid invoking the
backtracker for long strings of %.
Davis
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Progressively slow pattern match
2006-05-17 20:00 ` Alan Mackenzie
@ 2006-05-17 21:13 ` Ralf Angeli
0 siblings, 0 replies; 10+ messages in thread
From: Ralf Angeli @ 2006-05-17 21:13 UTC (permalink / raw)
Cc: emacs-devel
* Alan Mackenzie (2006-05-17) writes:
> On Wed, 17 May 2006, Ralf Angeli wrote:
>
>>The original regexp looks something like
>>"\\(%+[ \t]*\\)*foo"
>>in order to match stuff like
>>%% %% %% foo
>
> Use "\\(%+[ \t]+\\)%*foo"
Thanks for all the explanations and suggestions, also from Kevin,
David and Stuart. So it really was a badly written regexp. \c:
I think I'll settle with
"\\(%[% \t]*\\)?foo"
That means David's suggestion with an added "?" in order for it to
match a bare "foo" without preceding comment characters as well. For
me it looks like the one easiest to understand.
--
Ralf
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Progressively slow pattern match
2006-05-17 19:33 Progressively slow pattern match Ralf Angeli
2006-05-17 19:37 ` David Kastrup
2006-05-17 19:53 ` Alan Mackenzie
@ 2006-05-17 23:13 ` Richard Stallman
2 siblings, 0 replies; 10+ messages in thread
From: Richard Stallman @ 2006-05-17 23:13 UTC (permalink / raw)
Cc: emacs-devel
This problem is documented under the definition of * in regexps in the
Lisp manual. I made the text a little clearer and a little louder, in case
that helps.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2006-05-17 23:13 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-17 19:33 Progressively slow pattern match Ralf Angeli
2006-05-17 19:37 ` David Kastrup
2006-05-17 19:50 ` Kevin Rodgers
2006-05-17 19:50 ` Ralf Angeli
2006-05-17 20:00 ` Alan Mackenzie
2006-05-17 21:13 ` Ralf Angeli
2006-05-17 20:04 ` David Kastrup
2006-05-17 20:21 ` Stuart D. Herring
2006-05-17 19:53 ` Alan Mackenzie
2006-05-17 23:13 ` Richard Stallman
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.