Re: Smart strings & memory allocation
| From: | Stanislav Malyshev | Date: | Wed, 18 Jun 2003 13:21:30 +0000 |
| Subject: | Re: Smart strings & memory allocation | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-2363@lists.php.net to get a copy of this message | ||
SS>> Common referred to real applications, not 'make test'.
Do you have some data about real applications in PHP that use strings
longer than 80 bytes via smart strings? My tests show most of the strings
used are small. Looking at the clients of this functions and taking into
account that prontf's are usually small and long printf are usually or
rewritten into heredocs (which don't use smart strings) or separated into
different functions.
BTW, why do you think "make test" is a bad test of memory allocation
patterns? What do you propose as a better test?
SS>> In fact, whenever strings are not allocated through the
SS>> engine, 80 bytes is a really poor choice, because the malloc
SS>> implementation will very likely allocate a 128 byte chunk
SS>> anyway.
That's very bad news, because actually my test show that about 95% of
mallocs are for sizes below 100 bytes. But I hope the system malloc has
some mechanism to deal with it, otherwise we are wasting a real lot of
memory. Actually, given that tests show 90% of mallocs are for sizes below
64 bytes, if what you say is right, PHP's memory footprint is at least
twice as big as it is meant to be.
The number 80 was chosen because even if malloc allocates 128 bytes, these
128 bytes would be reused using the Zend memory cache. However, if the
size of the segment does not allow it to be into the Zend memory cache,
new malloc would be attempted each time. That was the primery rationale
for the change, not the memory-saving argument, though it is important
too.
BTW, the number 128 in the code allocated in fact at least 148 bytes, and
I don't know what malloc implemetation would do of this.
--
Stanislav Malyshev, Zend Products Engineer
stas@zend.com http://www.zend.com/ +972-3-6139665 ext.109