ID:               32727
 Updated by:       [EMAIL PROTECTED]
 Reported By:      cws at miraclenet dot co dot th
-Status:           Open
+Status:           Feedback
 Bug Type:         Performance problem
 Operating System: FreeBSD
 PHP Version:      4.3.11
 New Comment:

Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

PHP 5.1-dev has got some optimizing done in this part, see if it's any
better (without your patch of course)



Previous Comments:
------------------------------------------------------------------------

[2005-04-16 13:39:18] cws at miraclenet dot co dot th

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; \
        }\
 }

------------------------------------------------------------------------

[2005-04-16 13:08:32] 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. 



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=32727&edit=1

Reply via email to