Re: Structured Code vs. Performance
| From: | Stut | Date: | Thu, 29 Nov 2007 12:53:15 +0000 |
| Subject: | Re: Structured Code vs. Performance | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-265211@lists.php.net to get a copy of this message | ||
Jochem Maas wrote:
Stut wrote:Hopefully he's reading and will be able to give us a definitive answer. I'm going by my experience of stepping through code with Zend Studio, but it's possible (probably likely) that ZE does something slightly different when a debugger is attached. -Stut -- http://stut.net/Jo chem baas 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 { } }Stut wrote: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.Jochem Maas wrote: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?news_yodpeirs@thoftware.de wrote: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.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)