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

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

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
February 18, 2008 01:05
Subject:
Re: Slowdown of "sort keys %hash" under "use locale"
Message ID:
b77c1dce0802180105o1f8dd449vbab4244988169fa9@mail.gmail.com
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.

Thread Previous | Thread Next


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