ID: 32727
Comment by: ale at FreeBSD dot org
Reported By: cws at miraclenet dot co dot th
Status: Open
Bug Type: Feature/Change Request
Operating System: FreeBSD
PHP Version: 5.*, 4.*
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2007-06-05 08:37:30] runner at protom dot org
I hope this patch to be taken in main
------------------------------------------------------------------------
[2005-04-19 02:48:30] cws at miraclenet dot co dot th
I forget to mension that the previous result is
from my patched version.
The result of unpatch one is
c...@t42# ./php test_serialize.php
version:4.3.11
Length: 2798041
Serialize time: elapse(2.554760)
------------------------------------------------------------------------
[2005-04-19 02:36:12] cws at miraclenet dot co dot th
No it don't help me to speed up my test code.
This is the result
c...@t42$ ./php test.php
Content-type: text/html
X-Powered-By: PHP/5.1.0-dev
<PRE>version:5.1.0-dev
Length: 2798041
Serialize time: elapse(2.136879)
c...@t42$ /usr/local/bin/php test.php
<PRE>version:4.3.11
Length: 2798041
Serialize time: elapse(0.200818)
The test code and data can be download at
http://freebie.miraclenet.co.th/tmp/test_serialize.tgz
The test data may seem too extreme (an array of 2.8M) but it is the one
that our customer really use.
------------------------------------------------------------------------
[2005-04-16 16:38:42] [email protected]
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)
------------------------------------------------------------------------
[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; \
}\
}
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/32727
--
Edit this bug report at http://bugs.php.net/?id=32727&edit=1