You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bugs@httpd.apache.org by bu...@apache.org on 2013/02/10 18:20:33 UTC

[Bug 54543] New: Compile regex only when need

https://issues.apache.org/bugzilla/show_bug.cgi?id=54543

            Bug ID: 54543
           Summary: Compile regex only when need
           Product: Apache httpd-2
           Version: 2.4.3
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: mod_rewrite
          Assignee: bugs@httpd.apache.org
          Reporter: david@ols.es
    Classification: Unclassified

Regular expressions are compiled (with ap_pregcomp) when parsing the
configuration regardless if they will end being used or not.

If it makes sense i can submit a patch that will not compile the regex and
substitute the calls to ap_regexec to calls to a function that will compile the
regex if x->regex is null so only really need regex will be compiled

I think this could improve performance a bit, specially when using END/L flags
and when the request matches the first rules, and will not affect performance
in other cases. Anyway i could implement this as an option if you guys think
that it will be better that way.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org


[Bug 54543] Compile regex only when need

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54543

--- Comment #1 from David Saez <da...@ols.es> ---
Created attachment 29945
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=29945&action=edit
Patch that add NPC new RewriteRule flag

When a RewriteRule has the NPC flag the rule will not be regex-compiled until
the rule needs to be applied.

This flag only have sense and will only work for rules inside .htaccess files.
Also the affected rule will be compiled each time is need so it should not be
applied to rules that could be re-evaluated on the same request, usually this
means that it should only be used when you are sure that the rule will not be
evaluated again in the same request.

for example, if we are using some kind of php based CMS that resides on the
root of the server and handles dynamic requests through index.php and uses SEO
url's using mod_rewrite in a .htaccess file like this:

# avoid applying more rules to static content
RewriteRule ^(css|js|i)/.+   - [L,QSA]

# dinamic content
RewriteRule ^([a-z]+)/([0-9]+)$ /index.php?section=$1&id=$2 [END,NS,QSA]

# and a lot of similar rules ...

Now, all rules in the .htaccess file are always compiled, even for static
content requests. We can avoid this and even avoid in many cases having to
compile all rules for dinamic content using the NPC flag:

# avoid applying any rule to static content
RewriteRule ^(css|js|i)/.+   - [L,QSA]

# dinamic content
RewriteRule ^([a-z]+)/([0-9]+)$ /index.php?section=$1&id=$2 [END,NS,QSA,NPC]

in this case for static content matched by the first rule no other rule having
NPC will be compiled thus saving the time need for regex compilation

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org


[Bug 54543] Compile regex only when need

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54543

David Saez <da...@ols.es> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |PatchAvailable

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org