Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60653 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33427 invoked from network); 22 May 2012 14:06:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 May 2012 14:06:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=tom@punkave.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tom@punkave.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain punkave.com designates 209.85.213.170 as permitted sender) X-PHP-List-Original-Sender: tom@punkave.com X-Host-Fingerprint: 209.85.213.170 mail-yx0-f170.google.com Received: from [209.85.213.170] ([209.85.213.170:41492] helo=mail-yx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 26/02-22099-A7D9BBF4 for ; Tue, 22 May 2012 10:06:50 -0400 Received: by yenm2 with SMTP id m2so6071853yen.29 for ; Tue, 22 May 2012 07:06:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=WRVvJTsZOwv7A4KY37ZFdgJRMoe0GBOdKx9fgQVNq3g=; b=NPVRGLwPN9twHTQY5iUvqHrtlFEWcejxcfF2VcHXwGtNi6r660ZaFNnEk91Oho5As9 1Yl5PYaRL7nU1OeQCKOswohYgndjj7PyeK44xE/oJ/teUl+W/OXarvSpBkj6mccEOKjI H1jnQ3COi7KQ0rB9IydKBP8gU0dLOnOSCY4urYIF09mYra+7ZezJiifiuvZsxwk/llYA 3FZhfHrSA47TzgapNDDr8vX6hyAX5Zt+bk14n/AY506hiSxMpyhRSqSprQxKdjjQkPLF bJC8uBA1wNHHRBPTCkA2HIgMg7Ab6ZPix+ud1t6ZQ+bBm40xzaSSXL0+e+88QHdwSZEB IYgw== MIME-Version: 1.0 Received: by 10.236.76.133 with SMTP id b5mr28210151yhe.3.1337695607131; Tue, 22 May 2012 07:06:47 -0700 (PDT) Received: by 10.100.109.13 with HTTP; Tue, 22 May 2012 07:06:46 -0700 (PDT) In-Reply-To: References: <4FBA8FB0.80104@sugarcrm.com> Date: Tue, 22 May 2012 10:06:46 -0400 Message-ID: To: PHP Internals Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQm9mCNwx7psLOHjkXDzFtglC/U7e0TLSPbrliJKCv6a7s7Rro9xbgVykgx9RyCmTlrqDYSH Subject: Re: [PHP-DEV] memory usage ouchy From: tom@punkave.com (Tom Boutell) Actually, I just updated Rasmus' demo program to use assocative arrays instead of objects. In PHP 5.4.x, the associative array version uses more memory than the object oriented version. That's because PHP 5.4.x is using a flat array for predeclared properties, as was mentioned earlier by Gustavo. Associative arrays: 524288 bytes Objects: 262144 bytes The object-oriented version is also faster, by about 20%. Interestingly these results don't change much if I make the property names/keys much shorter. Probably there's a minimum allocation of 64 bytes for these or something. It would appear there is no longer a penalty simply for using many objects vs. many associative arrays in PHP 5.4. The opposite, in fact. I'm sure arrays didn't get slower, but objects now take advantage of some optimizations that become possible when properties are predeclared. However this doesn't mean that calling lots of setters will necessarily be as fast as direct property access... oh what the heck, let's test that too: Calling dead-simple setters for the four properties rather than setting them directly slows down the OOP version to the point where it runs at just about the same speed as the associative array version. That's not terrible. Direct property access is still fastest (after all that's what the setters do after they pay the overhead of the function call). On Mon, May 21, 2012 at 9:23 PM, Richard Lynch wrote: > No offense intended, but if you've got so many OOP objects flying > around that they are sucking down that much memory... > > You probably need to refactor your code and just "don't do that" > > Just my opinion. > > -- > brain cancer update: > http://richardlynch.blogspot.com/search/label/brain%20tumor > Donate: > https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FS9NLTNEEKWBE > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > -- Tom Boutell P'unk Avenue 215 755 1330 punkave.com window.punkave.com