Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
enterxssub: add CvXSCV bit
Browse files Browse the repository at this point in the history
Stored in the stash GV for all registered XS methods, to be picked up
by METHOD_CHECK_CACHE, to change the next op to XS.
clear it on redefinition as PP.

testsuite benchmark:
7% faster than without the bit.
overall ~3.5% faster then without enterxssub compile-time optimization.
only faster with some XS calls. Minor slowdown (<1%) without any XS call.
  • Loading branch information
rurban committed May 31, 2017
1 parent 3194fe3 commit 596c328
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .git-rr-cache
Submodule .git-rr-cache updated 37 files
+18,850 −0 13d6f8d2907b2b7697abdec05873f008b8f7f44d/postimage
+18,855 −0 13d6f8d2907b2b7697abdec05873f008b8f7f44d/preimage
+18,922 −0 1a464b2bcfceca02f631bd68111fb2026b3ac3b5/preimage
+18,825 −0 1f74a2aadd0e9fc9c5791fc2e0c066db441536e3/postimage
+18,835 −0 1f74a2aadd0e9fc9c5791fc2e0c066db441536e3/preimage
+18,829 −0 35c90063d30a13d4c5899b55249ceff5364e91a7/postimage
+18,834 −0 35c90063d30a13d4c5899b55249ceff5364e91a7/preimage
+19,724 −0 36ac5615d9ba3e4113517fa1293751246b653e52/postimage
+19,750 −0 36ac5615d9ba3e4113517fa1293751246b653e52/preimage
+16,874 −0 3877b4ea1c63e9c94143015ece4f093a9b20d600/postimage
+16,896 −0 3877b4ea1c63e9c94143015ece4f093a9b20d600/preimage
+13,622 −0 431abfa3f795be98a511109e64093168adf558ec/postimage
+13,627 −0 431abfa3f795be98a511109e64093168adf558ec/preimage
+11,016 −0 44daa7afa88677eebc8c14c9e48b744d1dc349e2/postimage
+11,019 −0 44daa7afa88677eebc8c14c9e48b744d1dc349e2/preimage
+18,822 −0 6e0e6a02d8b793bf7114bb985401cdf46e8f5e21/postimage
+18,827 −0 6e0e6a02d8b793bf7114bb985401cdf46e8f5e21/preimage
+1,844 −0 75811e1ed435c85f575d1370dcb8fd599b85d503/postimage
+1,849 −0 75811e1ed435c85f575d1370dcb8fd599b85d503/preimage
+2,117 −0 960e8a0b5454b9bcee643ca0d2e6e43910e6a71f/postimage
+2,120 −0 960e8a0b5454b9bcee643ca0d2e6e43910e6a71f/preimage
+13,642 −0 a10c37f89707e284a1e3bfcf05600d6f12afdaf6/postimage
+13,646 −0 a10c37f89707e284a1e3bfcf05600d6f12afdaf6/preimage
+16,872 −0 adabb4faec0dd26392727bf7ae09e341cf8b276f/postimage
+16,898 −0 adabb4faec0dd26392727bf7ae09e341cf8b276f/preimage
+18,836 −0 c6c18cf9533cad282ca870807bcefbef60015b0e/preimage
+13,642 −0 dc5d49f21f960295f44cdf3e6ec4a2de8fac949a/postimage
+13,645 −0 dc5d49f21f960295f44cdf3e6ec4a2de8fac949a/preimage
+18,818 −0 dc76edb966542aaf39a1d1ca7c0c9a1f21253d2c/postimage
+18,824 −0 dc76edb966542aaf39a1d1ca7c0c9a1f21253d2c/preimage
+649 −0 e5123d5a11afef540369b21050531d89446b1189/postimage
+674 −0 e5123d5a11afef540369b21050531d89446b1189/preimage
+18,842 −0 e6c4d11d49bdb06ec46ac26dcab85ef6262061ac/preimage
+648 −0 ebdc9579980b1b9ebb77d37407b805e9fe6372d0/postimage
+651 −0 ebdc9579980b1b9ebb77d37407b805e9fe6372d0/preimage
+18,885 −0 ee1f71062a5f39106935b416e51f0f652c7c40e7/postimage
+18,907 −0 ee1f71062a5f39106935b416e51f0f652c7c40e7/preimage
1 change: 1 addition & 0 deletions dump.c
Expand Up @@ -1711,6 +1711,7 @@ const struct flag_to_name gv_flags_names[] = {
{GVf_MULTI, "MULTI,"},
{GVf_ASSUMECV, "ASSUMECV,"},
{GVf_STATIC, "STATIC,"},
{GVf_XSCV, "XSCV,"},
};

const struct flag_to_name gv_flags_imported_names[] = {
Expand Down
6 changes: 6 additions & 0 deletions gv.h
Expand Up @@ -176,6 +176,7 @@ Return the CV from the GV.
#define GVf_IMPORTED_AV 0x20
#define GVf_IMPORTED_HV 0x40
#define GVf_IMPORTED_CV 0x80
#define GVf_XSCV 0x100

#define GvINTRO(gv) (GvFLAGS(gv) & GVf_INTRO)
#define GvINTRO_on(gv) (GvFLAGS(gv) |= GVf_INTRO)
Expand Down Expand Up @@ -211,6 +212,11 @@ Return the CV from the GV.
#define GvIMPORTED_CV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_CV)
#define GvIMPORTED_CV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_CV)

/* for the cache only */
#define GvXSCV(gv) (GvFLAGS(gv) & GVf_XSCV)
#define GvXSCV_on(gv) (GvFLAGS(gv) |= GVf_XSCV)
#define GvXSCV_off(gv) (GvFLAGS(gv) &= ~GVf_XSCV)

#ifndef PERL_CORE
# define GvIN_PAD(gv) 0
# define GvIN_PAD_on(gv) NOOP
Expand Down
14 changes: 9 additions & 5 deletions op.c
Expand Up @@ -10220,6 +10220,7 @@ Perl_newXS_len_flags(pTHX_ const char *name, STRLEN len,
}
}

GvXSCV_on(gv);
CvGV_set(cv, gv);
if (filename) {
/* XSUBs can't be perl lang/perl5db.pl debugged
Expand Down Expand Up @@ -18620,11 +18621,14 @@ Perl_coresub_op(pTHX_ SV * const coreargssv, const int code,

/*
=for apidoc report_redefined_cv

If a CV is overwritten, warn by whom
when use warnings 'redefine' is in effect.
=cut
*/
void
Perl_report_redefined_cv(pTHX_ const SV *name, const CV *old_cv,
SV * const *new_const_svp)
SV * const *new_const_svp)
{
const char *hvname;
bool is_const = !!CvCONST(old_cv);
Expand Down Expand Up @@ -18677,10 +18681,10 @@ Perl_report_redefined_cv(pTHX_ const SV *name, const CV *old_cv,
} else {
no_caller:
Perl_warner(aTHX_ packWARN(WARN_REDEFINE),
is_const
? "Constant subroutine %" SVf " redefined"
: "Subroutine %" SVf " redefined",
SVfARG(name));
is_const
? "Constant subroutine %" SVf " redefined"
: "Subroutine %" SVf " redefined",
SVfARG(name));
}
}
}
Expand Down
48 changes: 42 additions & 6 deletions pod/perlcdelta.pod
Expand Up @@ -110,16 +110,52 @@ as an updated module in the L</Modules and Pragmata> section.

=head1 Performance Enhancements

XXX Changes which enhance performance without changing behaviour go here.
There may well be none in a stable release.

[ List each enhancement as a =item entry ]

=over 4

=item *

XXX
XS calls were made faster again. Previously cperl (with 5.22.1c) fell
from pure perl calls to XS calls and changed the call type to
ENTERXSSUB for faster subsequent invocations. This made bigger
examples ~10% faster. Now the compiler detects calls to XS code and
changes the type to ENTERXSSUB. Also the method cache code checks now
for an XS call and changes the type of the next OP. Overall the
improvement is ~3.5%, but it depends on the frequency of XS
calls. It's 0.5-1% slower without any XS call. Note that p5p decided
to delete this feature request from it's TODO list.

The optree is a bit slimmer.
Before:

$ cperl5.27.0d-nt -Dt -e'use strict'
(-e:1) nextstate
(-e:1) const(PV("strict.pm"))
(-e:1) require
(-e:1) nextstate
(-e:1) pushmark
(-e:1) const(PV("strict"))
(-e:1) method_named(->import)
(-e:1) entersub(strict::import)
(-e:1) enterxssub(strict::import)
(-e:1) leavesub

Now:

$ cperl5.27.1d-nt -Dt -e'use strict'
(-e:1) nextstate
(-e:1) const(PV("strict.pm"))
(-e:1) require
(-e:1) nextstate
(-e:1) pushmark
(-e:1) const(PV("strict"))
(-e:1) method_named(->import)
(-e:1) enterxssub(strict::import)
(-e:1) leavesub

Note that this is still not optimal, as strict::import can be
compile-time optimized from a dynamic method call to a static function
call. A regression from 5.22.1c.
See L<http://blogs.perl.org/users/rurban/2011/06/how-perl-calls-subs-and-methods.html>

=back

Expand Down
3 changes: 2 additions & 1 deletion pp_hot.c
Expand Up @@ -5429,6 +5429,7 @@ PP(pp_method)
RETURN;
}

/* collapsed the XS check into one bit in the cached gv: GvXSCV */
#define METHOD_CHECK_CACHE(stash,cache,meth) \
if (SvREADONLY(stash) && !hv_exists_ent(stash, meth, 0)) { ; \
} else { \
Expand All @@ -5439,7 +5440,7 @@ PP(pp_method)
== (PL_sub_generation + HvMROMETA(stash)->cache_gen))) \
{ \
CV *cv = GvCV(gv); \
if (CvISXSUB(cv) && !CvCONST(cv) && CvROOT(cv) && !PL_perldb \
if (GvXSCV(gv) && !PL_perldb \
&& OpTYPE(PL_op->op_next) == OP_ENTERSUB) \
{ \
DEBUG_k(Perl_deb(aTHX_ "method_named -> xs %" SVf "\n",\
Expand Down
2 changes: 2 additions & 0 deletions sv.c
Expand Up @@ -4129,6 +4129,8 @@ Perl_gv_setref(pTHX_ SV *const dstr, SV *const sstr)
? cv_const_sv((const CV *)sref)
: NULL;
HV * const stash = GvSTASH((const GV *)dstr);
if (GvXSCV(dstr) && (const_sv || !CvISXSUB(cv)))
GvXSCV_off(dstr);
report_redefined_cv(
sv_2mortal(
stash
Expand Down

0 comments on commit 596c328

Please sign in to comment.