To answer the question you asked: Yes, replacing nested capturing subgroups with non-capturing parens will improve the performance of your regexes.

In a rather crude test, almost exactly 1 order of magnitude improvement for each pair of capturing parens that you replace. That is m[((?:xxx)(?:yyy))]g runs almost exactly twice as fast as m[((xxx)(yyy))]g; and m[((?:xxx)(?:yyy)(?:zzz))]g runs almost exactly 3 times faster than m[((xxx)(yyy)(zzz))]g;; and so on.

In that test, I was assigning all the captures to an array, which obviously results in differing numbers of values in the arrays.

If you are only refering to the captures you are interested in by their aliases ($1, and ignoring $2 and $3 etc.), then the impact of using the capturing parens that you don't need is less (around 15%), but it is still significant.

The upshot is: only capture what you need, and use non-capturing parens anywhere else.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: Speeding up a large regex match pattern by BrowserUk
in thread Speeding up a large regex match pattern by wossname

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.