Revision: 1040
Author: [email protected]
Date: Fri Jan 22 03:32:44 2010
Log: Add a cache for CORE:$opname, to save repeatedly regenerating the same SVs.

cachegrind suggests that this reduces I references by 2%, for my arbitrary test
case.
http://code.google.com/p/perl-devel-nytprof/source/detail?r=1040

Modified:
 /trunk/NYTProf.xs

=======================================
--- /trunk/NYTProf.xs   Thu Jan 21 07:48:03 2010
+++ /trunk/NYTProf.xs   Fri Jan 22 03:32:44 2010
@@ -349,6 +349,8 @@

static unsigned int ticks_per_sec = 0; /* 0 forces error if not set */

+static AV *slowop_name_cache;
+
 /* prototypes */
 static void output_header(pTHX);
 static unsigned int read_int(void);
@@ -2175,8 +2177,25 @@
             subr_entry->called_subnam_sv = newSVpv(slowop_name, 0);
         }
else { /* 2 == put slowops into multiple packages */
+            SV **opname = NULL;
+            SV *sv;
+            if (!slowop_name_cache)
+                slowop_name_cache = newAV();
+            opname = av_fetch(slowop_name_cache, op_type, TRUE);
+            if (!opname)
+ croak("panic: opname cache read for '%s' (%d)\n", slowop_name, op_type);
+            sv = *opname;
+
+            if(!SvOK(sv)) {
+                const STRLEN len = strlen(slowop_name);
+                sv_grow(sv, 5 + len + 1);
+                memcpy(SvPVX(sv), "CORE:", 5);
+                memcpy(SvPVX(sv) + 5, slowop_name, len + 1);
+                SvCUR_set(sv, 5 + len);
+                SvPOK_on(sv);
+            }
+            subr_entry->called_subnam_sv = SvREFCNT_inc(sv);
             subr_entry->called_subpkg_pv = CopSTASHPV(PL_curcop);
- subr_entry->called_subnam_sv = newSVpvf("CORE:%s", slowop_name);
         }
         subr_entry->called_cv_depth = 1; /* an approximation for slowops */
         subr_entry->called_is_xs = "sop";

--
You've received this message because you are subscribed to
the Devel::NYTProf Development User group.

Group hosted at:  http://groups.google.com/group/develnytprof-dev
Project hosted at:  http://perl-devel-nytprof.googlecode.com
CPAN distribution:  http://search.cpan.org/dist/Devel-NYTProf

To post, email:  [email protected]
To unsubscribe, email:  [email protected]

Reply via email to