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 /sv.h | |
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 'sv.h')
-rw-r--r-- | sv.h | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -360,6 +360,7 @@ perform the upgrade if necessary. See C<svtype>. subroutine in another package. Set the GvIMPORTED_CV_on() if it needs to be expanded to a real GV */ +#define SVpad_NAMELIST SVp_SCREAM /* AV is a padnamelist */ #define SVf_IsCOW 0x00010000 /* copy on write (shared hash key if SvLEN == 0) */ #define SVs_PADTMP 0x00020000 /* in use as tmp; only if ! SVs_PADMY */ @@ -489,7 +490,7 @@ union _xmgu { MAGIC* xmg_magic; /* linked list of magicalness */ HV* xmg_ourstash; /* Stash for our (when SvPAD_OUR is true) */ STRLEN xmg_hash_index; /* used while freeing hash entries */ -}; +}; /* also used by PadnamelistMAXNAMED */ struct xpv { _XPV_HEAD; |