Fwd: Re: [PHP-DEV] Re: PHP 5.1 roadmap

From: Date: Fri, 05 Nov 2004 20:55:07 +0000
Subject: Fwd: Re: [PHP-DEV] Re: PHP 5.1 roadmap
Groups: php.internals 
Request: Send a blank email to internals+get-13739@lists.php.net to get a copy of this message
Still behind a bit on my email. Has anyone tested this yet? It would be cool to commit. >Delivered-To: alias-zend-andi@zend.com >Date: Sun, 24 Oct 2004 13:10:20 +0200 (CEST) >From: Sascha Schumann <sascha@schumann.cx> >X-X-Sender: sas@lx >To: Wez Furlong <kingwez@gmail.com> >Cc: Andi Gutmans <andi@zend.com>, internals <internals@lists.php.net> >Subject: Re: [PHP-DEV] Re: PHP 5.1 roadmap >X-Security: message sanitized on mail.zend.com > See > http://www.impsec.org/email-tools/sanitizer-intro.html > for details. $Revision: 1.143 $Date: 2004-04-10 09:05:42-07 >X-Bogosity: No, tests=bogofilter, spamicity=0.000000, version=0.13.6.2 > > > The specific case I had was serializing an array containing a whole > > bunch of arrays representing the data from tables in a database. I > > don't recall how many rows there were, but the serialized data was > > around 5 MB. This was on windows, and feels like realloc doing > > over-time, so a fix could be something as simple as tweaking the > > smart_str chunking code; start with a fair initial size and perhaps > > having it double the size on each realloc. > > The default values you find inside php_smart_str.h are tuned > for efficient usage of the engine's allocator. They are not > tuned for huge real-world usage. > > The attached patch should change that for var.c. > > - Sascha >

Index: php_smart_str.h =================================================================== RCS file: /repository/php-src/ext/standard/php_smart_str.h,v retrieving revision 1.28 diff -u -r1.28 php_smart_str.h --- php_smart_str.h 8 Jan 2004 17:32:51 -0000 1.28 +++ php_smart_str.h 24 Oct 2004 11:09:23 -0000 @@ -40,6 +40,10 @@ #define SMART_STR_START_SIZE 78 #endif +#ifndef SMART_STR_DOUBLE_ALLOC +#define SMART_STR_DOUBLE_ALLOC 0 +#endif + #ifdef SMART_STR_USE_REALLOC #define SMART_STR_REALLOC(a,b,c) realloc((a),(b)) #else @@ -49,6 +53,21 @@ #define SMART_STR_DO_REALLOC(d, what) \ (d)->c = SMART_STR_REALLOC((d)->c, (d)->a + 1, (what)) +#if SMART_STR_DOUBLE_ALLOC == 1 + +#define SMART_STR_NEW_SIZE(d, newlen) do { \ + do { \ + (d)->a <<= 1; \ + } while (newlen >= (d)->a); \ +} while (0) +#else + +#define SMART_STR_NEW_SIZE(d, newlen) do { \ + (d)->a = newlen + SMART_STR_PREALLOC; \ +} while (0) + +#endif + #define smart_str_alloc4(d, n, what, newlen) do { \ if (!(d)->c) { \ (d)->len = 0; \ @@ -60,7 +79,7 @@ } else { \ newlen = (d)->len + (n); \ if (newlen >= (d)->a) { \ - (d)->a = newlen + SMART_STR_PREALLOC; \ + SMART_STR_NEW_SIZE(d, newlen); \ SMART_STR_DO_REALLOC(d, what); \ } \ } \ Index: var.c =================================================================== RCS file: /repository/php-src/ext/standard/var.c,v retrieving revision 1.196 diff -u -r1.196 var.c --- var.c 8 Oct 2004 19:02:00 -0000 1.196 +++ var.c 24 Oct 2004 11:09:23 -0000 @@ -30,6 +30,11 @@ #include "php.h" #include "php_string.h" #include "php_var.h" + +#define SMART_STR_PREALLOC 1 +#define SMART_STR_START_SIZE 2048 +#define SMART_STR_DOUBLE_ALLOC 1 + #include "php_smart_str.h" #include "basic_functions.h" #include "php_incomplete_class.h"
« previous php.internals (#13739) next »