summaryrefslogtreecommitdiff
path: root/mro.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-11-16 10:00:50 -0800
committerFather Chrysostomos <sprout@cpan.org>2012-11-17 10:13:43 -0800
commit8c34e50dccefe2a0539ba2339a2889bb841986c2 (patch)
treec70c4467270f2e76d3e10faa1fdca9b902e109fa /mro.c
parentc342cf44e9b6e2978a5bf7f3037755edf7df5fac (diff)
downloadperl-8c34e50dccefe2a0539ba2339a2889bb841986c2.tar.gz
[perl #114864] Don’t use amt for DESTROY
DESTROY has been cached in overload tables since perl-5.6.0-2080-g32251b2, making it 4 times faster than before (over- load tables are faster than method lookup). But it slows down symbol lookup on stashes with overload tables, because overload tables use magic, and SvRMAGICAL results in calls to mg_find on every hash lookup. By reusing SvSTASH(stash) to cache the DESTROY method (if the stash is unblessed, of course, as most stashes are), we can avoid making all destroyable stashes magical and also speed up DESTROY lookup slightly more. The results: • 10% increase in stash lookup speed after destructors. That was just testing $Foo::{x}. Other stash lookups will have other overheads that make the difference less impressive. • 5% increase in DESTROY lookup speed. I was using an empty DESTROY method to test this, so, again, real DESTROY methods will have more overhead and less speedup.
Diffstat (limited to 'mro.c')
-rw-r--r--mro.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/mro.c b/mro.c
index 1264754128..2d1d887fe8 100644
--- a/mro.c
+++ b/mro.c
@@ -544,6 +544,9 @@ Perl_mro_isa_changed_in(pTHX_ HV* stash)
/* Changes to @ISA might turn overloading on */
HvAMAGIC_on(stash);
+ /* DESTROY can be cached in SvSTASH. */
+ if (!SvOBJECT(stash)) SvSTASH(stash) = NULL;
+
/* Iterate the isarev (classes that are our children),
wiping out their linearization, method and isa caches
and upating PL_isarev. */
@@ -1327,6 +1330,9 @@ Perl_mro_method_changed_in(pTHX_ HV *stash)
/* Inc the package generation, since a local method changed */
HvMROMETA(stash)->pkg_gen++;
+ /* DESTROY can be cached in SvSTASH. */
+ if (!SvOBJECT(stash)) SvSTASH(stash) = NULL;
+
/* If stash is UNIVERSAL, or one of UNIVERSAL's parents,
invalidate all method caches globally */
if((stashname_len == 9 && strEQ(stashname, "UNIVERSAL"))