Re: Opcode caching and conditional includes

From: Date: Thu, 05 Jul 2007 21:34:04 +0000
Subject: Re: Opcode caching and conditional includes
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-47237@lists.php.net to get a copy of this message
__autoload() has the same effect as a conditional since it's called at runtime once the original source code pass couldn't locate the requested class file and waits until all other classes are loaded correctly and before making the __autoload() callback. Just like conditionals, unless it's a conditional class definition the file is however cached - the class just needs to be redrawn on every request since it's only accessed at runtime past the point the opcode cache can cache that step. It really is important that how much is cached is recognised. The file is *always* cached - the act of pulling out specific classes and functions for use (not an internals guru so someone probably knows what I'm hitting vaguely ;)) isn't. In most cases the second part has a much smaller performance gain than the file cache bit. Paddy Pádraic Brady http://blog.astrumfutura.com http://www.patternsforphp.com ----- Original Message ---- From: Paul M Jones <pmjones@ciaweb.net> To: PEAR developer mailinglist <pear-dev@lists.php.net> Sent: Thursday, July 5, 2007 6:29:13 PM Subject: [PEAR-DEV] Opcode caching and conditional includes On Jul 5, 2007, at 12:00 PM, till wrote: > On 7/5/07, Paul M Jones <pmjones@ciaweb.net> wrote: >> On Jul 4, 2007, at 11:16 AM, Till Klampaeckel wrote: >> >> > Till Klampaeckel (http://pear.php.net/user/till) has voted +1 on >> > the proposal for Encryption::Crypt_HMAC2. >> > >> > Proposal information: >> > http://pear.php.net/pepr/pepr-proposal-show.php?id=495 >> > Vote information: >> > Ëî >> > Útàà‰ôGN@‰alhttp://pear.php.net/pepr/pepr-vote-show.php?id=495&handle=till >> > >> > This vote is conditional. The condition is: >> > >> > * lazy loading breaks bytecode caching >> >> Is that so? I know that conditional class *definition* causes >> bytecode-cache misses, but I was not aware that conditional include/ >> require would cause trouble. Can you link to a reference on this? > > From what I understand, it attemps to cache the file, but since the > include is inside a condition and runtime dependent, it would break > the cache when the condition is evaluated. Or maybe even every time > (disclaimer: not sure). > > Since lazyloading (autoload, conditional includes, etc.) in general is > runtime dependent - that defeats the entire caching. > > I know it's convenient. ;-) Correct me if I am wrong. I don't know if you are wrong; I can only speak from my memory and experience. I could well be wrong myself. My understanding was that once a class is loaded via require/include to the opcode cache, it remains available on subsequent runs. That the require/include occurs within an if() is of little or no consequence to the opcode cache. E.g., this is not a problem ... if ($condition) { include "/path/to/file.php"; } .. because the bytecode cache retains in memory the opcodes for that file, and has in-memory access to it on subsequent runs when the condition is met. It won't need to load from the filesystem every time, just the first time the file needed. If calling require/include within an if() *is* a problem, then doing an include from within (for example) a function or method would also be a problem. This is because that function/method is called "at runtime" (as you say). I don't believe such is the case. What *is* trouble to the opcode cache are conditional class definitions. The opcode cache doesn't know what the class "really" is until runtime, so it can't cache the opcodes for the class. It might change on each run of the script. if ($condition) { class Foo extends Bar { // ... } } else { class Foo extends Zim { // ... } } Again, I could be incorrect here. How this affects __autoload() is beyond me. -- Paul M. Jones <http://paul-m-jones.com> Solar: Simple Object Library and Application Repository for PHP5. <http://solarphp.com> Join the Solar community wiki! <http://solarphp..org> Savant: The simple, elegant, and powerful solution for templates in PHP. <http://phpsavant.com> -- PEAR Development Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ____________________________________________________________________________________Ready for the edge of your seat? Check out tonight's top picks on Yahoo! TV. http://tv.yahoo.com/

« previous php.pear.dev (#47237) next »