develooper Front page | perl.perl5.porters | Postings from March 2017

Re: [perl #129802] Regexp performance problem with swiped strings(?)

Thread Previous
From:
Dave Mitchell
Date:
March 27, 2017 10:51
Subject:
Re: [perl #129802] Regexp performance problem with swiped strings(?)
Message ID:
20170327105110.GN3342@iabyn.com
On Tue, Oct 04, 2016 at 09:42:51PM +0300, Niko Tyni wrote:
> On Tue, Oct 04, 2016 at 09:08:02AM +0100, Dave Mitchell wrote:
> > On Mon, Oct 03, 2016 at 01:15:27PM -0700, Niko Tyni wrote:
> > > # New Ticket Created by  Niko Tyni 
> > > # Please include the string:  [perl #129802]
> > > # in the subject line of all future correspondence about this issue. 
> > > # <URL: https://rt.perl.org/Ticket/Display.html?id=129802 >
> 
> > > As reported by Leszek Dubiel in <https://bugs.debian.org/839600>,
> > > there seems to be a regexp performance problem for certain inputs.
> 
> > This is down to a limitation in the COW implementation. Perl stores the
> > copy-on-write reference count in the spare byte (if any) just after the \0
> > at the end of the string. Depending on how the string has been allocated
> > and/or grown, it may not have  a spare byte, and so the string has to be
> > copied after a match rather than COWed (the copy is so that $1, $2, $`, $&
> > etc remain with the correct values even if the string is subsequently
> > modified).
> > 
> > The PADTMP commit is not really relevant - it just happens to alter the
> > particular route by which a string ended up with SvCUR+1 == SvLEN.
> > 
> > You can see a similar slowdown on old perls (5.16.0 and earlier) if you
> > add $& somewhere in the test code - then all 3 cases run pathologically
> > slow.
> > 
> > The whole COW/SvGROW interaction is on my list of things to do.
> 
> Many thanks for the explanation. Shouldn't the /n regexp modifier help
> in that case? It doesn't seem to.

No, because  /n only converts some or all (..)'s into (?:...)'s. It doesn't
affect $`,$&,$'. So the string still needs to be retained.

-- 
Please note that ash-trays are provided for the use of smokers,
whereas the floor is provided for the use of all patrons.
    -- Bill Royston

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About