Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46726 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8089 invoked from network); 14 Jan 2010 01:44:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jan 2010 01:44:31 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.220.227 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.220.227 mail-fx0-f227.google.com Received: from [209.85.220.227] ([209.85.220.227:58987] helo=mail-fx0-f227.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 71/6F-00773-EF67E4B4 for ; Wed, 13 Jan 2010 20:44:31 -0500 Received: by fxm27 with SMTP id 27so362227fxm.23 for ; Wed, 13 Jan 2010 17:44:27 -0800 (PST) Received: by 10.103.126.40 with SMTP id d40mr43305mun.23.1263433463562; Wed, 13 Jan 2010 17:44:23 -0800 (PST) Received: from ?192.168.200.22? (c-98-234-184-167.hsd1.ca.comcast.net [98.234.184.167]) by mx.google.com with ESMTPS id u9sm371324muf.54.2010.01.13.17.44.22 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 13 Jan 2010 17:44:23 -0800 (PST) Message-ID: <4B4E76F3.6070509@lerdorf.com> Date: Wed, 13 Jan 2010 17:44:19 -0800 User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Tim Starling CC: internals@lists.php.net References: <4B4DABED.4060202@easyflirt.com> <4B4DBF40.5040801@easyflirt.com> <4B4DCFDA.6090206@dmi.me.uk> <4B4DF01A.1080103@wikimedia.org> <4B4DFBDE.1020906@lerdorf.com> <4B4E5943.3000706@wikimedia.org> <4B4E5D5B.9020805@zend.com> <4B4E6BE5.1070404@wikimedia.org> In-Reply-To: <4B4E6BE5.1070404@wikimedia.org> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] About optimization From: rasmus@lerdorf.com (Rasmus Lerdorf) Tim Starling wrote: > class C { > var $v1, $v2, $v3, $v4, $v5, $v6, $v7, $v8, $v9, $v10; > } > > $m = memory_get_usage(); > $a = array(); > for ( $i = 0; $i < 10000; $i++ ) { > $a[] = new C; > } > print ((memory_get_usage() - $m) / 10000) . "\n"; > ?> > > 1927 bytes (I'll use 64-bit from now on since it gives the most shocking > numbers) PHP 5.3.3-dev (cli) (built: Jan 11 2010 11:26:25) Linux colo 2.6.31-1-amd64 #1 SMP Sat Oct 24 17:50:31 UTC 2009 x86_64 php > class C { php { var $v1, $v2, $v3, $v4, $v5, $v6, $v7, $v8, $v9, $v10; php { } php > php > $m = memory_get_usage(); php > $a = array(); php > for ( $i = 0; $i < 10000; $i++ ) { php { $a[] = new C; php { } php > print ((memory_get_usage() - $m) / 10000) . "\n"; 1479.5632 So you need 1500 bytes per object in your array. I still fail to see the problem for a web request. Maybe I am just old-fashioned in the way I look at this stuff, but if you have more than 1000 objects loaded on a single request, you are doing something wrong as far as I am concerned. This is why we do things like unbuffered mysql queries, zero-copy stream passing, etc. We never want entire result sets or entire files in memory because even if we optimize the crap out of it, it is still going to be way faster to simply not do that. -Rasmus