Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: An optimization of last resort: eliminate capturing from your regexps

by Aristotle (Chancellor)
on Jul 24, 2006 at 22:04 UTC ( [id://563396]=note: print w/replies, xml ) Need Help??


in reply to Re: An optimization of last resort: eliminate capturing from your regexps
in thread An optimization of last resort: eliminate capturing from your regexps

If a pattern doesn’t contain (?{}) or (??{}) bits, then $str cannot change during a match. So in that case it would be feasible to postpone the memcpy until right after the match (before the regex engine returns) and memcpy only the matched bits. That way, all regexen which don’t run Perl code would automatically avoid unnecessary copying. I think that would be a worthwhile patch.

Makeshifts last the longest.

  • Comment on Re^2: An optimization of last resort: eliminate capturing from your regexps

Replies are listed 'Best First'.
Re^3: An optimization of last resort: eliminate capturing from your regexps
by diotalevi (Canon) on Jul 24, 2006 at 23:06 UTC

    I think that's what it does already.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      That would contradict tye’s explanation:

      Capturing in a regex imparts a performance hit because it means that a copy will be made of the string that the regex is being applied to (which makes it a worse performance hit when matching against really large strings – one of the worst cases being running a lot of little regexes with capturing against the same huge string, something a parser is likely to do).

      I don’t see how what tye said would apply if perl already behaved the way I said it should.

      Makeshifts last the longest.

        Perl makes a copy if there is capturing or PL_saw_ampersand is true. I think you said that perl makes that copy immediately on partial success or similar. I responded saying that I think perl waits until the match has succeeded to make the copy. I don't think what I just said contradicts tye at all especially as tye is also right.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://563396]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-23 19:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found