diff options
author | Reini Urban <rurban@x-ray.at> | 2014-08-27 12:48:35 -0500 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2014-08-27 18:17:58 -0700 |
commit | 880c169bb2bd5e6e9ae996842d6860bf88d28585 (patch) | |
tree | 93a20b983f965fbde2d289710c6375f475424a30 | |
parent | 8f1287bb93a0c5357089ec22fdc1c5ff9b19875e (diff) | |
download | perl-880c169bb2bd5e6e9ae996842d6860bf88d28585.tar.gz |
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.
-rw-r--r-- | sv.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -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 |