Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13739 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17322 invoked by uid 1010); 5 Nov 2004 20:55:04 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 17292 invoked from network); 5 Nov 2004 20:55:03 -0000 Received: from unknown (HELO mail.zend.com) (80.74.107.235) by pb1.pair.com with SMTP; 5 Nov 2004 20:55:03 -0000 Received: (qmail 16482 invoked from network); 5 Nov 2004 20:55:02 -0000 Received: from localhost (HELO AndiNotebook.zend.com) (127.0.0.1) by localhost with SMTP; 5 Nov 2004 20:55:02 -0000 Message-ID: <5.1.0.14.2.20041105125445.0427b610@localhost> X-Sender: andi@localhost X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Fri, 05 Nov 2004 12:55:07 -0800 To: internals@lists.php.net Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=====================_361719545==_" Subject: Fwd: Re: [PHP-DEV] Re: PHP 5.1 roadmap From: andi@zend.com (Andi Gutmans) --=====================_361719545==_ Content-Type: text/plain; charset="us-ascii"; format=flowed 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 >X-X-Sender: sas@lx >To: Wez Furlong >Cc: Andi Gutmans , internals >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 > --=====================_361719545==_ Content-Type: text/plain; charset="us-ascii" Content-Disposition: attachment; filename="tune-smart-str-var.c" 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" --=====================_361719545==_--