Re: Structured Code vs. Performance
| From: | Jochem Maas | Date: | Thu, 29 Nov 2007 12:51:09 +0000 |
| Subject: | Re: Structured Code vs. Performance | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-265210@lists.php.net to get a copy of this message | ||
Stut wrote:
> Jo chem baas wrote:
>> Stut wrote:
>>> Jochem Maas wrote:
>>>> news_yodpeirs@thoftware.de wrote:
>>>>> I got different portions of code only used for certain purposes (who
>>>>> don't ;-)?). But what, in your opinion (better: in your experience)
>>>>> would be the best regarding script-performance: Putting each
>>>>> code-portion in a separate file and include it if required, putting
>>>>> it in a constant-dependent if-structure (if (defined('FOO')
>>>>> && FOO)
>>>>> {class foo{}; function foo(); ...})
>>>> defining functions or classes conditionally is not recommended,
>>>> because it
>>>> means they can only be defined at runtime and not compile time ...
>>>> which will
>>>> kill any op-code caching you might have in place or use in future
>>>> (e.g. php.net/apc)
>>> I'm not completely sure, but I think you're wrong there. Removing the
>>> condition in the example above will not affect any opcode caching since
>>> PHP cannot determine the result of that conditional until runtime.
>>
>> one of us is reading the other's post incorrectly - I have a feeling
>> we are
>> both trying to say the same thing.
>>
>> namely runtime class definitions don't have the same benefit of
>> op-code caching
>> as compiletime definitions.
>>
>> or not?
>
> Not ;). There is no such thing as a compile-time definition in PHP.
>
> Whether there is conditional definition or not, the opcode cache will
> look the same. The reason for this is that function and class
> definitions happen at runtime not compile time. This would have to be
> the case for conditional definition to work at all, since the compiler
> cannot determine the value of a condition at compile-time.
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 { }
}
>
> -Stut
>