Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60628 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38847 invoked from network); 21 May 2012 18:47:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 May 2012 18:47:56 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 74.125.82.54 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 74.125.82.54 mail-wg0-f54.google.com Received: from [74.125.82.54] ([74.125.82.54:44094] helo=mail-wg0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 35/C3-16352-BDD8ABF4 for ; Mon, 21 May 2012 14:47:56 -0400 Received: by wgbfg15 with SMTP id fg15so4295440wgb.11 for ; Mon, 21 May 2012 11:47:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type :x-gm-message-state; bh=3d3kL/f91di32kgxuH7cUMMSKGqzThDra1Udgcezw5U=; b=fvxGHnhBaTRC8q17uf/gRBiKVMrqUncL3olqqAdQTsuDCzSTDuM1/Tva0oi18m9XMW Ujxbi2k79NvuxwnqnUtXGPQqajLmt3qfXe2Zu0iq+jfCtfEadb8Ly30bH6cqjqY2KeNz 6ru7H912vbdeV/wvHV3p8R/MjzP3oFCnN+sL4SLJLOVbUcqlG6eg7AsBj6ssbfwN+Ppa 7DtmsXTN0sDzJyoDLoag7b9u9Jt94USqkXZEJkflMwKD5/BqcLu3jzvZF2BQM6h0Yqf4 ExZK+ZLu4rMi3M55+aLm6O0lIzt2inRf/yZ4DZquAQe2Nx8Ap4WzDr273tKx01LG1uXK e6RA== MIME-Version: 1.0 Received: by 10.180.86.197 with SMTP id r5mr27815323wiz.21.1337626071749; Mon, 21 May 2012 11:47:51 -0700 (PDT) Received: by 10.216.237.100 with HTTP; Mon, 21 May 2012 11:47:51 -0700 (PDT) Date: Mon, 21 May 2012 14:47:51 -0400 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQlj58cvIiiaIWwa4B0OT3hb+cM1QCiiJxuozrusVJOpp8hsvDqj/b393MdV/r56ndMzGHM4 Subject: memory usage ouchy From: rasmus@mindplay.dk (Rasmus Schultz) I just realized something that never occurred to me before - every property is actually stored as a hash. This test-script will demonstrate: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 'a'; $foo->bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = 'b'; $foo->cccccccccccccccccccccccccccccccccccccccccccccccccccc = 'c'; $foo->dddddddddddddddddddddddddddddddddddddddddddddddddddd = 'd'; $bytes += 4; $test[] = $foo; } $after = memory_get_usage(true); header('Content-type: text/plain'); echo ($after-$before).' bytes used; '.$bytes.' bytes of information stored.'; Output is this: 786432 bytes used; 4000 bytes of information stored. I know this an extreme example, I just did it to see if what I suspected was actually correct. How come it's necessary to store the property-names of every property in every object? For properties that have been defined in classes, why can't they be stored in a more efficient manner? (using lookup tables) I know the nature of PHP is dynamic, and I know that dynamic properties would have to be stored in a key/value form internally... but if you look at modern PHP software, dynamic properties is actually something very few people use. My suspicion is that all this memory-overhead has performance implications as well? Allocating and deallocating memory for all of these repeated property-names, it can't be very efficient? I don't know much about the inner workings of PHP or C in general, but if the property-names are in deed stored repeatedly, and if the string-type uses a pointer, wouldn't it possible to point all of the property-name strings to same address in memory, sharing the property-name strings, instead of storing them repeatedly? Just a thought...