diff options
author | Ilya Zakharevich <ilya@math.ohio-state.edu> | 1997-04-01 11:34:37 -0500 |
---|---|---|
committer | Chip Salzenberg <chip@atlantic.net> | 1997-04-01 12:01:35 +1200 |
commit | 1bd69d1d0fa002def016e601cb71bfcd93600bd3 (patch) | |
tree | 9d8a7737d797f321df03e777f814632c9f7e9666 | |
parent | c9d716f75179fb7a413359cd6453141dfe552e82 (diff) | |
download | perl-1bd69d1d0fa002def016e601cb71bfcd93600bd3.tar.gz |
Reduce memory footprint of literal strings
Subject: Fix for memory allocation on 'string'
Currently qq/a/ takes 2/3 of memory of "a" or 'a'. Test with
> env PERL_DEBUG_MSTATS=2 perl -e '$#a=10000; $a[$i] = qq// while $i++ <10000'
Memory allocation statistics after compilation: (buckets 8..8192)
17552 free: 0 9 24 16 16 3 1 2 1 0 1
43888 used: 0 119 232 176 16 5 3 10 0 0 1
Total sbrk(): 61800. Odd ends: sbrk(): 360, malloc(): 0 bytes.
Memory allocation statistics after execution: (buckets 8..65536)
17136 free: 0 121 21 15 16 3 1 0 1 0 1 0 0 0
515344 used: 0 10119 235 177 16 5 3 250 0 0 1 0 0 1
Total sbrk(): 532840. Odd ends: sbrk(): 360, malloc(): 0 bytes.
> env PERL_DEBUG_MSTATS=2 perl -e '$#a=10000; $a[$i] = "a" while $i++ <10000'
Memory allocation statistics after compilation: (buckets 8..8192)
17520 free: 0 9 23 16 16 3 1 2 1 0 1
43920 used: 0 119 233 176 16 5 3 10 0 0 1
Total sbrk(): 61800. Odd ends: sbrk(): 360, malloc(): 0 bytes.
Memory allocation statistics after execution: (buckets 8..65536)
17616 free: 0 121 4 15 16 3 1 1 1 0 1 0 0 0
713520 used: 0 10119 10236 177 16 5 3 131 0 0 1 0 0 1
Total sbrk(): 731496. Odd ends: sbrk(): 360, malloc(): 0 bytes.
The following patch fixes it:
p5p-msgid: 1997Apr1.113438.1913905@hmivax.humgen.upenn.edu
-rw-r--r-- | toke.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -622,7 +622,11 @@ sublex_start() return THING; } if (op_type == OP_CONST || op_type == OP_READLINE) { - yylval.opval = (OP*)newSVOP(op_type, 0, q(lex_stuff)); + SV *sv = q(lex_stuff); + SV *sv1 = newSVpv(SvPV(sv, na), SvCUR(sv)); /* Make PV of PVIV. */ + + SvREFCNT_dec(sv); + yylval.opval = (OP*)newSVOP(op_type, 0, sv1); lex_stuff = Nullsv; return THING; } |