Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28250 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5968 invoked by uid 1010); 5 Mar 2007 22:43:44 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 5953 invoked from network); 5 Mar 2007 22:43:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Mar 2007 22:43:44 -0000 Authentication-Results: pb1.pair.com header.from=antony@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=antony@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 212.25.124.162 as permitted sender) X-PHP-List-Original-Sender: antony@zend.com X-Host-Fingerprint: 212.25.124.162 mail.zend.com Linux 2.5 (sometimes 2.4) (4) Received: from [212.25.124.162] ([212.25.124.162:46225] helo=mail.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 46/07-16561-D1D9CE54 for ; Mon, 05 Mar 2007 17:43:44 -0500 Received: (qmail 28335 invoked from network); 5 Mar 2007 22:41:49 -0000 Received: from internal.zend.office (HELO ?127.0.0.1?) (10.1.1.1) by internal.zend.office with SMTP; 5 Mar 2007 22:41:49 -0000 Message-ID: <45EC9D1B.6000804@zend.com> Date: Tue, 06 Mar 2007 01:43:39 +0300 User-Agent: Thunderbird 2.0b2 (X11/20070116) MIME-Version: 1.0 To: Brian Moon CC: internals@lists.php.net References: <45EC8CE9.8020807@dealnews.com> In-Reply-To: <45EC8CE9.8020807@dealnews.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] The way the engine works? From: antony@zend.com (Antony Dovgal) On 03/06/2007 12:34 AM, Brian Moon wrote: > Ok, I am no C coder and I don't claim to be very smart about low level > parts of PHP. But, IMO, this is bug. > > http://bugs.php.net/bug.php?id=36924 > > I have created a test script that shows the insanity of this bug: > > > $str = "This is a medium length string"; > > $start = memory_get_usage(); > for($x=1;$x<=100;$x++){ > echo $str.": (3.5): ".time()."\n"; > } > $first_growth = number_format(memory_get_usage() - $start); > > $start = memory_get_usage(); > for($x=1;$x<=100;$x++){ > echo "$str: (3.5): ".time()."\n"; > } > $growth = number_format(memory_get_usage() - $start); > > > echo "first growth: $first_growth\nsecond growth: $growth\n"; > > ?> Number of iterations | First growth | Second growth | Peak usage 100 480 bytes ~5Kb ~73Kb 100 000 556 bytes ~32Kb ~100Kb 1 000 000 556 bytes ~32Kb ~100Kb Tested with PHP 5.2.1 and 5.2.2-dev on Linux (with --disable-debug). > Now, you turn that into a script that is going to loop millions of > times, building strings to build data and run for hours. The next thing > you know, your cron job is using 450MB of memory and you try to figure > out what YOU did wrong. Hours later you find this little jewel waiting > for you and realize you did not do anything wrong. You just used the > language. Yup, the language stole ~32Kb of your memory and used it to speedup the allocation of small chunks. > Everyone ignored my last email about memory waste and large arrays. I > can only assume that you will ignore this one too. > I am starting to see why Stefan became so bitter. > I have always tried to squash the "myth" that putting variables inside > strings in PHP was bad, but now, I think I will flip on that. > I tested as far back as PHP 4.3.9 and as new as 5.2.1. -- Wbr, Antony Dovgal