From 880c169bb2bd5e6e9ae996842d6860bf88d28585 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Wed, 27 Aug 2014 12:48:35 -0500 Subject: [PATCH] sv_grow: performance improvement for short strings Empty COW strings with CUR=0 ended up allocated as LEN=10. Now they are rounded up to 4 or 8. Timings: +0 16.394324103 0.27% +2 16.114379842 0.01% +4 16.305622265 1.03% +8 16.337438609 1.30% +10 16.675009468 0.59% with LD_LIBRARY_PATH=`pwd` perf stat -r2 ./perl t/harness t/op/*.t +2 was consistently the best number, and +10 the worst. --- sv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sv.c b/sv.c index 5a77d6b..2940942 100644 --- a/sv.c +++ b/sv.c @@ -1553,7 +1553,7 @@ Perl_sv_grow(pTHX_ SV *const sv, STRLEN newlen) #ifdef PERL_NEW_COPY_ON_WRITE /* the new COW scheme uses SvPVX(sv)[SvLEN(sv)-1] (if spare) - * to store the COW count. So in general, allocate one more byte than + * to store the CowREFCNT. So in general, allocate one more byte than * asked for, to make it likely this byte is always spare: and thus * make more strings COW-able. * If the new size is a big power of two, don't bother: we assume the @@ -1569,7 +1569,7 @@ Perl_sv_grow(pTHX_ SV *const sv, STRLEN newlen) if (newlen > SvLEN(sv)) { /* need more room? */ STRLEN minlen = SvCUR(sv); - minlen += (minlen >> PERL_STRLEN_EXPAND_SHIFT) + 10; + minlen += (minlen >> PERL_STRLEN_EXPAND_SHIFT) + 2; if (newlen < minlen) newlen = minlen; #ifndef PERL_UNWARANTED_CHUMMINESS_WITH_MALLOC -- 1.8.3.1