diff options
author | Father Chrysostomos <sprout@cpan.org> | 2013-07-29 20:40:24 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2013-07-30 06:30:39 -0700 |
commit | 7db6405c07905ec5bc4178ea8184089842949690 (patch) | |
tree | f45de0317bdf2e3aad3035a0c51fe26163cafd88 /dump.c | |
parent | 533d93cc1b438187c43582769dc47b2f8c1797a3 (diff) | |
download | perl-7db6405c07905ec5bc4178ea8184089842949690.tar.gz |
Skip trailing constants when searching pads
Under ithreads, constants and GVs are stored in the pad.
When names are looked up up in a pad, the search begins at the end and
works its way toward the beginning, so that an $x declared later masks
one declared earlier.
If there are many constants at the end of the pad, which can happen
for generated code such as lib/unicore/TestProp.pl (which has about
100,000 lines and over 500,000 pad entries for constants at the
end of the file scope’s pad), it can take a long time to search
through them all.
Before commit 325e1816, constants used &PL_sv_undef ‘names’. Since
that is the default value for array elements (when viewed directly
through AvARRAY, rather than av_fetch), the pad allocation code did
not even bother storing the ‘name’ for these. So the name pad (aka
padnamelist) was not extended, leaving just 10 entries or so in the
case of lib/unicore/TestProp.pl.
Commit 325e1816 make pad constants have &PL_sv_no names, so the
name pad would be implicitly extended as a result of storing
&PL_sv_no, causing a huge slowdown in t/re/uniprops.t (which runs
lib/unicore/TestProp.pl) under threaded builds.
Now, normally the name pad *does* get extended to match the pad,
in pad_tidy, but that is skipped for string eval (and required
file scope, of course). Hence, wrapping the contents of
lib/unicore/TestProp.pl in a sub or adding ‘my $x’ to end of it will
cause the same slowdown before 325e1816.
lib/unicore/TestProp.pl just happened to be written (ok, generated) in
such a way that it ended up with a small name pad.
This commit fixes things to make them as fast as before by recording
the index of the last named variable in the pad. Anything following
that is disregarded in pad lookup and search begins with the last
named variable. (This actually does make things faster before for
subs with many trailing constants in the pad.)
This is not a complete fix. Adding ‘my $x’ to the end of a large file
like lib/unicore/TestProp.pl will make it just as slow again.
Ultimately we need another algorithm, such as a binary search.
Diffstat (limited to 'dump.c')
-rw-r--r-- | dump.c | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -1515,7 +1515,8 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo if (SvWEAKREF(sv)) sv_catpv(d, "WEAKREF,"); } append_flags(d, flags, second_sv_flags_names); - if (flags & SVp_SCREAM && type != SVt_PVHV && !isGV_with_GP(sv)) { + if (flags & SVp_SCREAM && type != SVt_PVHV && !isGV_with_GP(sv) + && type != SVt_PVAV) { if (SvPCS_IMPORTED(sv)) sv_catpv(d, "PCS_IMPORTED,"); else @@ -1563,6 +1564,7 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo if (SvPAD_STATE(sv)) sv_catpv(d, "STATE,"); goto evaled_or_uv; case SVt_PVAV: + if (AvPAD_NAMELIST(sv)) sv_catpvs(d, "NAMELIST,"); break; } /* SVphv_SHAREKEYS is also 0x20000000 */ @@ -1705,6 +1707,9 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo HV * const ost = SvOURSTASH(sv); if (ost) do_hv_dump(level, file, " OURSTASH", ost); + } else if (SvTYPE(sv) == SVt_PVAV && AvPAD_NAMELIST(sv)) { + Perl_dump_indent(aTHX_ level, file, " MAXNAMED = %"UVuf"\n", + (UV)PadnamelistMAXNAMED(sv)); } else { if (SvMAGIC(sv)) do_magic_dump(level, file, SvMAGIC(sv), nest+1, maxnest, dumpops, pvlim); @@ -1730,7 +1735,11 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo PerlIO_putc(file, '\n'); Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)AvFILLp(sv)); Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)AvMAX(sv)); - Perl_dump_indent(aTHX_ level, file, " ARYLEN = 0x%"UVxf"\n", SvMAGIC(sv) ? PTR2UV(AvARYLEN(sv)) : 0); + /* arylen is stored in magic, and padnamelists use SvMAGIC for + something else. */ + if (!AvPAD_NAMELIST(sv)) + Perl_dump_indent(aTHX_ level, file, " ARYLEN = 0x%"UVxf"\n", + SvMAGIC(sv) ? PTR2UV(AvARYLEN(sv)) : 0); sv_setpvs(d, ""); if (AvREAL(sv)) sv_catpv(d, ",REAL"); if (AvREIFY(sv)) sv_catpv(d, ",REIFY"); |