develooper Front page | perl.perl5.porters | Postings from September 2017

[perl #132171] Minor speedup improvement for pp_require

Thread Previous | Thread Next
From:
Tony Cook via RT
Date:
September 27, 2017 01:18
Subject:
[perl #132171] Minor speedup improvement for pp_require
Message ID:
rt-4.0.24-18441-1506475115-231.132171-15-0@perl.org
On Tue, 26 Sep 2017 16:21:01 -0700, atoomic wrote:
> Just ran some basic benchmark with/without the patch on top of
> blead=dc41635313 using Porting/bench.pl tool and the following
> command:
> 
> ./perl -Ilib Porting/bench.pl --benchfile=../benchmark-tests
> ../perl2/perl=blead ./perl=blead+patch
> 
> Of course, the result highly depends on the test used, I try to
> provide some basic scenarii with short and long module names existing
> or not.
> 
> Feel free to comment on it

--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3752,6 +3752,7 @@ S_require_file(pTHX_ SV *sv)
     I32 old_savestack_ix;
     const bool op_is_require = PL_op->op_type == OP_REQUIRE;
     const char *const op_name = op_is_require ? "require" : "do";
+    SV ** svp_cached = NULL;
 
     assert(op_is_require || PL_op->op_type == OP_DOFILE);
 
@@ -3761,6 +3762,15 @@ S_require_file(pTHX_ SV *sv)
     if (!(name && len > 0 && *name))
         DIE(aTHX_ "Missing or undefined argument to %s", op_name);
 
+#ifndef VMS
+	/* try to return earlier (save the SAFE_PATHNAME check) if INC already got the name */
+	if (op_is_require) {
+		/* can optimize to only perform one single lookup */
+		SV ** svp_cached = hv_fetch(GvHVn(PL_incgv), (char*) name, len, 0);

This declares a new svp_cached, so the initial svp_cached isn't modified.

+		if ( svp_cached && *svp_cached != &PL_sv_undef ) RETPUSHYES;
+	}
+#endif
+



@@ -3799,8 +3809,8 @@ S_require_file(pTHX_ SV *sv)
 	unixlen = len;
     }
     if (op_is_require) {
-	SV * const * const svp = hv_fetch(GvHVn(PL_incgv),
-					  unixname, unixlen, 0);
+	/* reuse the previous hv_fetch result if possible */
+	SV * const * const svp = svp_cached ? svp_cached : hv_fetch(GvHVn(PL_incgv), unixname, unixlen, 0);
 	if ( svp ) {
 	    if (*svp != &PL_sv_undef)
 		RETPUSHYES;
-- 

so svp_cached is always NULL here.

Tony

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=132171

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About