Tom Anderson | 17 Aug 16:22

Re: Performance tip

Ivan Ristic wrote:
> I thought you might find this interesting:
> http://www.modsecurity.org/blog/archives/2006/08/modsecurity_per.html
> 
 > So instead of:
 >
 > SecFilterSelective VAR KEYWORD1
 > SecFilterSelective VAR KEYWORD2
 > SecFilterSelective VAR KEYWORD3
 >
 > from now on you want to write:
 >
 > SecFilterSelective VAR (KEYWORD1|KEYWORD2|KEYWORD3)

It is the regex engine which makes this more efficient.  It would be 
even faster if you wrote:

SecFilterSelective VAR KEYWORD(1|2|3)

And even faster still like this:

SecFilterSelective VAR KEYWORD(?:1|2|3)

It has to do with redundant code and memory allocation in the first 
instance, reduction of backtracking in the second, and saving memory in 
the third.

Regarding readability, as far as I'm concerned, the shorter the better, 
which is why condensed regexes are great.  If you cannot read regexes, 
that's what comments are for.  But let's get serious -- any sysadmin 
worth his salt needs to know how to read and write regular expressions. 
  To me, a regular expression is far more readable than a long English 
comment or a multi-line block of code.  If you have to translate it, do 
so in a comment, but you shouldn't really need subtitles to use a common 
system tool like regexes unless some particular pattern is really 
convoluted or tricky.

Tom

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

Gmane