Depends on which version of Apache and mod_perl you're using. Personally, I only have experience with the Apache 1.X series and the Apache 2.X with the prefork MPM.

The way I understand it, is that Apache 1.X and 2.X (prefork MPM) start a Perl interpreter at server load time (well, actually two times, but that doesn't matter here right now). Any modules loaded at server startup time, either through directives in the Apache configuration, or in a PerlRequire file, become part of that interpreter. If any of the special regex variables is seen at that time, then all processes that fork off the initial process (the Apache children that do the actual handling of the requests), will have the regex execution speed penalty.

If the special regex variables have not been seen, each Apache child starts out with a fast regex. But as soon as any of the children load code that use the special regexes, then that request and all future requests of that child will have the slower regex performance.

One way to get around that would be to have the child die after handling a request that loaded a module with the special regex characters (see $r->child_terminate). Forking nowadays is pretty fast. On the other hand, the loading of that module might occur often enough to make it worthwhile to keep the child anyway. YMMV.

Now, with Apache 2 with MPM's other than prefork, I understand there's actually a pool of Perl interpreters each with their own characteristics. So it should be possible to have a Perl interpreter with the magic regex characters enabled in it, and one that doesn't. On the other hand, you seem to need a threaded Perl in those situations (someone please correct me if I'm wrong), which has its own drawbacks execution speed wise.

I think in conclusion I would have to say: don't use (modules that use) "$&", "$`" or "$'". Or don't worry about the execution speed penalty.

In general, I would worry less about execution speed in mod_perl, but more about shared memory usage. If your server goes into swap, who cares about slower regexes?

Hope this helps.

Liz


In reply to Re: Naughty Regular Expressions and mod_perl by liz
in thread Naughty Regular Expressions and mod_perl by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.