Re: [APC-DEV] APC and autoloading

[email protected] (Rasmus Lerdorf) Mon, 25 Sep 2006 01:22:00 -0700
Newsgroups php.apc.dev
Message-ID <[email protected]>
David Zülke wrote:
> Hi folks,
> 
> I hope this is the right place for my question ;)
> 
> Over at the Propel (http://propel.phpdb.org) Dev Mailing List, we're 
> discussing moving to autoloading completely. Someone then mentioned the 
> following ticket: http://pecl.php.net/bugs/bug.php?id=8765
> 
> Is it indeed accurate that APC doesn't accelerate _anything_ if a class 
> is loaded via autoloading? I know it doesn't work well with _onces, but 
> PHP 5.2 fixes that from what I understand.
> 
> I always thought autoloading was the way to go, since it's not doing a 
> _once (for obvious reasons), and it's only loading stuff on demand, so I 
> assumed it to be the fastest of all possible solutions.
> 
> I'd greatly appreciate any insight on this "issue".

Gopal summed it up nicely.  It boils down to the fact that anything you 
push down into the executor is going to be slower than the same thing 
done in the compile phase.  This is not an APC-specific thing, but a 
generic characteristic of any cache that caches the output of the 
compile phase.  Any sort of runtime definition of classes or functions 
is going to be slower than compile-time.  It's not hard to figure out 
what will be slow and what won't be.  Just think about whether something 
can be completely defined without actually executing your script.

eg.

<?php
   class foo() { }
?>

can be defined at compile-time.

<?php
   if(cond) (
     class foo() { }{
   }
?>

can't be, since we have to execute the script to evaluate the condition 
before we know whether we should create the class.

-Rasmus