summaryrefslogtreecommitdiff
path: root/pad.h
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2013-07-29 20:40:24 -0700
committerFather Chrysostomos <sprout@cpan.org>2013-07-30 06:30:39 -0700
commit7db6405c07905ec5bc4178ea8184089842949690 (patch)
treef45de0317bdf2e3aad3035a0c51fe26163cafd88 /pad.h
parent533d93cc1b438187c43582769dc47b2f8c1797a3 (diff)
downloadperl-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 'pad.h')
-rw-r--r--pad.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/pad.h b/pad.h
index f6f3455148..2558b7ed3e 100644
--- a/pad.h
+++ b/pad.h
@@ -285,6 +285,8 @@ Restore the old pad saved into the local variable opad by PAD_SAVE_LOCAL()
#define PadnamelistARRAY(pnl) AvARRAY(pnl)
#define PadnamelistMAX(pnl) AvFILLp(pnl)
+#define PadnamelistMAXNAMED(pnl) \
+ ((XPVAV*) SvANY(pnl))->xmg_u.xmg_hash_index
#define PadARRAY(pad) AvARRAY(pad)
#define PadMAX(pad) AvFILLp(pad)