emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Documentation on debugging regexp performance


From: Alexis
Subject: Re: Documentation on debugging regexp performance
Date: Thu, 21 Jan 2016 20:39:42 +1100


Yuri Khan <address@hidden> writes:

I'm running into a surprising regular expressions issue. I have attached a file (~50k) in which (re-search-forward " +[^:=]+ +:=?") seems to be extremely slow. (I killed it after 30 seconds). Truncating the file to its first 20 lines reduces the time for re-search-forward to about a second, which is still extremely slow.

I’m no expert on the Emacs regexp implementation, but this part is ambiguous: "[^:=]+ +". The engine will have to backtrack at least once because the first part will greedily slurp all spaces, then the second part will not match. You might want to add the space to the exclusion character class: "[^:= ]+ +".

More generally, i highly recommend Jeffrey Friedl's book "Mastering Regular Expressions". It's not Emacs-specific, but it provides in-depth explanations of why certain regexen are time- and/or space-hungry.


Alexis.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]