|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-04-16 13:08 UTC] cws at miraclenet dot co dot th
Description: ------------ serialize use a lot of realloc which are very slow on FreeBSD From - http://rgarciasuarez.free.fr/p5p/p5p-200307-1.pod - Dan Kogai explained that FreeBSD comes with an implementation of malloc() that is optimized for paged memory, and safe from duplicate free() calls. But the downside is that realloc() is very slow. That's usually not a big deal, because most programs don't use realloc() very often -- but perl does. (The default configuration of perl on FreeBSD is to use perl's internal malloc, that hasn't this realloc limitation.) Serialize use a fix incremental value (SMART_STR_PREALLOC in php_smart_ptr.h). It better for serialize to use exponential incremential value to reduce number of realloc. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 07:00:01 2025 UTC |
This is a patch t42# diff -u ext/standard/php_smart_str.h /home/cws/php_smart_str.h --- ext/standard/php_smart_str.h Wed Apr 16 16:12:37 2003 +++ /home/cws/php_smart_str.h Sat Apr 16 18:27:30 2005 @@ -32,6 +32,10 @@ #define SMART_STR_PREALLOC 128 #endif +#ifndef SMART_PTR_MAX_PREALLOC +#define SMART_PTR_MAX_PREALLOC 1048576 +#endif + #ifdef SMART_STR_USE_REALLOC #define SMART_STR_REALLOC(a,b,c) realloc((a),(b)) #else @@ -42,8 +46,11 @@ if (!d->c) d->len = d->a = 0; \ newlen = d->len + n; \ if (newlen >= d->a) {\ - d->c = SMART_STR_REALLOC(d->c, newlen + SMART_STR_PREALLOC + 1, what); \ - d->a = newlen + SMART_STR_PREALLOC; \ + size_t pre_alloc = newlen *2;\ + if ( pre_alloc > SMART_PTR_MAX_PREALLOC ) { pre_alloc = SMART_PTR_MAX_PREALLOC; }\ + if ( pre_alloc < SMART_STR_PREALLOC) { pre_alloc = SMART_STR_PREALLOC; }\ + d->c = SMART_STR_REALLOC(d->c, newlen + pre_alloc + 1, what); \ + d->a = newlen + pre_alloc; \ }\ }Can you try the following patch and tell me the results and which FreeBSD version you are using? --- ext/standard/php_smart_str.h.orig 2009-07-14 14:08:07.000000000 +0200 +++ ext/standard/php_smart_str.h 2009-07-14 14:08:12.000000000 +0200 @@ -30,12 +30,14 @@ #define smart_str_0(x) do { \ if ((x)->c) { \ + (x)->a = (x)->len; \ + SMART_STR_DO_REALLOC(x, 0); \ (x)->c[(x)->len] = '\0'; \ } \ } while (0) #ifndef SMART_STR_PREALLOC -#define SMART_STR_PREALLOC 128 +#define SMART_STR_PREALLOC 1048576 #endif #ifndef SMART_STR_START_SIZE