develooper Front page | perl.perl5.porters | Postings from February 2008

Re: Slowdown of "sort keys %hash" under "use locale"

Thread Previous
From:
Marcus Holland-Moritz
Date:
February 18, 2008 10:15
Subject:
Re: Slowdown of "sort keys %hash" under "use locale"
Message ID:
20080218191444.32b9d4f3@r2d2
On 2008-02-18, at 10:05:31 +0100, Rafael Garcia-Suarez wrote:

> On 15/02/2008, Marcus Holland-Moritz <mhx-perl@gmx.net> wrote:
> > The reason for the slowdown is that the keys have become readonly
> > scalars, for which the results of strxfrm() isn't cached, so the
> > code spends most of the time doing strxfrm()'s.
> >
> > I've a simple fix for that: Also enable the caching for readonly
> > scalars. However, I'm not fully sure what the implications of this
> > change would be. According to sv_magicext()'s docs, it's perfectly
> > legal to attach magic to readonly SVs. However, most of the core
> > code explicitly doesn't attach magic to readonly SVs.
> >
> > The following patch removes the special treatment of readonly SVs
> > and restores the original speed.
> >
> > --- perl-current-orig-1/sv.c    2008-02-15 00:40:47.000000000 +0100
> > +++ perl-current-mhx-1/sv.c     2008-02-15 01:21:30.000000000 +0100
> > @@ -6494,11 +6494,6 @@
> >             Safefree(mg->mg_ptr);
> >         s = SvPV_const(sv, len);
> >         if ((xf = mem_collxfrm(s, len, &xlen))) {
> > -           if (SvREADONLY(sv)) {
> > -               SAVEFREEPV(xf);
> > -               *nxp = xlen;
> > -               return xf + sizeof(PL_collation_ix);
> > -           }
> >             if (! mg) {
> >  #ifdef PERL_OLD_COPY_ON_WRITE
> 
> I see no objection to this. This *should* work -- if there are unwanted
> side effects, that's probably due to bugs in the magic handling code.

Thanks! :-)

I've commited the above as change #33334.

Marcus

-- 
Rule of the Great:
	When people you greatly admire appear to be thinking deep
	thoughts, they probably are thinking about lunch.

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