Slow realloc

Chatchawan Wongsiriprasert cws at miraclenet.co.th
Tue Apr 19 17:30:56 PDT 2005


Hi,

    Last week I got a request from my customer to check that why his
PHP code run much slower on FreeBSD than the Linux machine. After sometime
of checking I found the the problem is in the PHP serialize function which
use a lot of realloc call with small (128 bytes) incremenent. I
had sumbited a small patch (http://bugs.php.net/bug.php?id=32727) to fix
the problem which decrease the run-time of a test code from 2 seconds to
0.2 second

    After check on gooble, I found that this is an intension in FreeBSD libc
design to increase the performance of malloc and sacrifice the less use
realloc (http://phk.freebsd.dk/pubs/malloc.pdf and
http://www.freebsd.org/cgi/query-pr.cgi?pr=61691)

    The question:

Is there another way to increase the performance of the program that use a
lot of small realloc call other than change the way that a program use
realloc (as I do and Poul-Henning Kamp suggest in pr61691)?

Becase the way I use need a lot of time to found where to fix and the fix is
localize (PHP also use realloc in other place such as string operation
which my patch does not fix -- so , concatenate a string runs 10 times
slower on FreeBSD than Linux).

Moreover, Linux realloc is fast , so many open source deveper that use
Linux as their main devepment system will overlook this problem (such as
in PHP case).

Regards,
Chatchwan Wongsiriprasert




More information about the freebsd-performance mailing list