Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49585 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6347 invoked from network); 8 Sep 2010 17:29:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Sep 2010 17:29:31 -0000 Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 217.114.211.66 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 217.114.211.66 unknown Solaris 10 (beta) Received: from [217.114.211.66] ([217.114.211.66:34285] helo=config.schlueters.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 09/51-33683-FE7C78C4 for ; Wed, 08 Sep 2010 13:29:20 -0400 Received: from [192.168.1.31] (ppp-93-104-103-54.dynamic.mnet-online.de [93.104.103.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by config.schlueters.de (Postfix) with ESMTPSA id 1CCC544D6E; Wed, 8 Sep 2010 19:29:16 +0200 (CEST) To: Guilherme Blanco Cc: Dmitry Stogov , Pierrick Charron , guilhermeblanco@hotmail.com, Zeev Suraski , PHP Internals In-Reply-To: References: <4C873C0F.1010200@zend.com> <4C879613.7090709@zend.com> Content-Type: text/plain; charset="UTF-8" Date: Wed, 08 Sep 2010 19:29:09 +0200 Message-ID: <1283966949.2118.146.camel@guybrush> Mime-Version: 1.0 X-Mailer: Evolution 2.30.2 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: PHP Annotations RFC + Patch From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) Hi, On Wed, 2010-09-08 at 13:44 -0300, Guilherme Blanco wrote: > >>> 2) I suppose that usage of annotation would be quite rare case. I don't > >>> think it make sense to extend each op_array, property and class with > >>> additional "annotations" field. I think it's possible to have a separate > >>> CG(annotaions_map) where the keys might be the addresses of corresponding > >>> classesm, methods and properties. > >> > >> Annotations are metadata related to a code element. IMHO it make sense > >> to add them in the appropriate code element structures (even > >> doc_comment is in those structures) so that APC and other cache will > >> know that this is something part of the code element and it needs to > >> be cached and so on. > > > > It's easier to keep it in appropriate places, but it's a waste of memory, > > because only a few classes will use it. According to doc comments, in case > > we accept annotations, I would represent it as a special kind of annotation. > > > > Separate map(enity -> anotations) would require memory only for defined > > annotations. Of course it would be a bit more expensive to read it and would > > require special handling in opcode hashes. > > Argument is not reasonable IMHO. > You may know that most code around web lack of documentation, > specially docblock, so why not separate the docblocks on a separate > structure too? > Sorry, but your argument is not reasonable. > Each class/property/method should contain all relevant information it > can get, whatever it needs (docblock, annotations, visibility > information, etc). Of course you have a bit of memory overhead, but > it's a pointer, isn't it? So at the end, we will only have overhead > when we have annotations defined. > Also, decomposing the annotation definition and storage adds a level > of dependency and indirection that may get things harder to comprehend > by newer contributors. Let's do some math: A pointer on a 64bit architecture is 8 bytes. A random PHP binary of mine has 1226 functions. And 133 classes. Each of them has, let's say 10 methods (i guess average is higher, but well). Then I'm running an application, which has maybe 100 classes with 10 methods each. This gives 8 * (1226 + 133 + 100 + (133 * 10) + (100 * 10)) bytes = 30.31 kilobytes. Now I have 100 server children, so this are 3.021 megabytes on the server. Oh and that's only for the pointer which _could_ point to annotations but will most likely point to NULL. With the approach proposed by Dmitry this memory won't be used but whenever annotations are accessed a lookup more will be needed. This calculation is of course completely wrong to many wild guesses and simplifications in there. Of course that's not much but your statement shows what will happen next: "specially docblock, so why not separate the docblocks" First of all I claim that there are more docblocks than annotations. Secondly what about the next pointer, and the next and the next somebody wants to add, not only in the op array but other global structures, one pointer in the zval, one in the hash bucket, one ...? We can still move this over later when annotations are adopted and the equation memory vs. CPU for this feature is valued differently. johannes