Re: Structured Code vs. Performance

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thursday 29 November 2007, Jochem Maas wrote:

> okay, but I was just paraphrasing the man Rasmus, although I admit I may
> have misinterpreted (or misundersstood the 'why') - thought I pretty sure
> he has written on a number of occasions that code like the following sucks
> for op-code caches and should be avoided:
>
> if (foo()) {
> 	class Foo { }
> }

That's bad because the compiler will *still* parse and compile class Foo(), 
but give it some ridiculous internal name so that it's inaccessible.  It will 
then, at runtime, conditionally give it a real name so that it then becomes 
accessible.  You'll still have the same cost to parse and compile class Foo() 
either way.  There is no savings in either compile time or memory use.

if (foo()) {
   include('foo.php');
}

This will make baby opcode cache cry, from what I understand, but will not 
balloon the memory usage the way the former code will.  In practice, though, 
a modular, pluggable system (most of what I use) is going to end up having 
conditional includes no matter what you do so I generally don't pay much 
attention to that type of optimization, since it's irrelevant to me anyway.

-- 
Larry Garfield			AIM: LOLG42
larry@xxxxxxxxxxxxxxxx		ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux