Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46731 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84081 invoked from network); 14 Jan 2010 11:48:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jan 2010 11:48:32 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@hristov.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@hristov.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain hristov.com from 85.92.87.36 cause and error) X-PHP-List-Original-Sender: php@hristov.com X-Host-Fingerprint: 85.92.87.36 iko.gotobg.net Linux 2.6 Received: from [85.92.87.36] ([85.92.87.36:42610] helo=iko.gotobg.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7E/BC-00773-F840F4B4 for ; Thu, 14 Jan 2010 06:48:32 -0500 Received: from e180232196.adsl.alicedsl.de ([85.180.232.196] helo=[192.168.1.127]) by iko.gotobg.net with esmtpa (Exim 4.69) (envelope-from ) id 1NVOBT-0001wH-S3; Thu, 14 Jan 2010 13:48:16 +0200 Message-ID: <4B4F0482.9020709@hristov.com> Date: Thu, 14 Jan 2010 12:48:18 +0100 User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Rasmus Lerdorf 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> <4B4E76F3.6070509@lerdorf.com> In-Reply-To: <4B4E76F3.6070509@lerdorf.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - iko.gotobg.net X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - hristov.com X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] About optimization From: php@hristov.com (Andrey Hristov) Rasmus Lerdorf wrote: > 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. actually with mysqlnd a buffered set might be faster, if you know what are you doing, because the data won't be copied once more. with unbuffered sets data is copied from the network buffer to the zval. With buffered sets the zval just pointes to the network buffer. If you have the RAM then buffered should be faster. Of course you should use the set and when finished close it and not fetch-close-process, because then copy is forced. Best, Andrey