3 ms·
> I work at a scale where this is extremely relevant Really? You run Facebook or something? Got any figures? > autoloading is a godsend. Manually including fi
by contingencies 14y ago
> I work at a scale where this is extremely relevant
Really? You run Facebook or something? Got any figures?
> autoloading is a godsend. Manually including files is not only error-prone, but is tedious and requires development effort [time] that would be best utilized elsewhere.
Hang on. How many files are you including? Generally you only need to include one, right. Your framework, maybe an external library. Then you can call in whatever modules you need, as you need them. Right? Or are you using some weird kind of framework without modules?
> > [...] this particular approach ('autoload') costs too much and delivers too little to be generally praiseworthy
> > [...] whilst harming simplcity
> Costs too much? Have you not implemented it? It's not hard at all to implement, even if you have an unorthodox file & class naming convention. The only caveat is that you can only have 1 class per file (which hopefully you'd agree is good practice in the first place).
To clarify, the overheads I was referring to were (1) conceptual; less "WTF" for new developers to deal with (2) complexity; code-flow is both simpler and more explicit.
> Performance increases can be pretty large, too, especially at scale. Consider...
If you can provide some demo code, I'd love to see it. I think you will find largely it's just a result of having a dumb framework or being ultra-contrived in your example to an unrealistic degree. I also think you'll find that second-guessing require_once (a language-level feature) is not going to be faster than simply using it.
- h2s 14y agoThis is a documented Zend Framework thing, so personally I wouldn't call it "contrived", "dumb" or "weird". http://till.typepad.com/blog/2008/10/zendframework-performance.html http://till.typepad.com/blog/2008/10/zendframework-performan... > Removing require_once in favour of __autoload shows > one of the biggest performance improvements in my > entire application - I shaved off roughly 220 > milliseconds by removing about 15 (or so) calls to > require_once in my bootstrap.php file. And that's > with APC enabled, and a decent sized realpath.cache > (and .ttl). Presumably this lazy loading approach starts being faster once your codebase exceeds a certain size. Everything you've said so far indicates that you tend to work on smaller, fire-and-forget PHP projects, so maybe this just doesn't resonate with your experience and I can certainly respect that. No matter what your gut feeling about language-level features may be, I know that at my day job, we measured a clear performance boost when we removed require_once and switched completely to autoloading. For those of us working on very large, long-term PHP codebases, autoloading really is a good thing and I hope you can respect that in return.
- contingencies 14y agoGood answer. I'm not saying that including code you don't want to use isn't going to shave of milliseconds, I'm just not convinced that the problem is being adequately identified. The problem honestly sounds like the codebase itself. And if that's something built with Zend, then perhaps that doesn't reflect well on Zend's innate structure, and Zend's only effective way around this is through 'autoload'.
- wvenable 14y ago> The problem honestly sounds like the codebase itself. Any reasonably sized codebase is going to load a lot of files. Because your projects are so small that this is not an issue is not a reflection on the quality of every one else's work.
- contingencies 14y agoThe subject of the conversation: "Given that (a) we need to load files (b) loading files takes time ... do we, consider performance: (1) use an autoloader on some mega-framework; or (2) be explicit and require directly." I feel this comment contributes nothing to the conversation but a baseless personal accusation.
- wvenable 14y agoOn the subject of the conversation, we can either let the computer do the work for us or waste time specifying it manually in a way that it's nearly impossible to do as effectively. The code is already explicit enough, requiring directly is pointless busy-work that is more likely to be wrong.
- k3n 14y ago> Really? You run Facebook or something? Got any figures? 100 total devs, over 10 years of development, with the codebase spanning 5k files and over 1 million LoC. > Hang on. How many files are you including? Generally you only need to include one, right. Your framework, maybe an external library. Then you can call in whatever modules you need, as you need them. Right? Or are you using some weird kind of framework without modules? This is a homebrew framework, but you're missing the point: regardless of how you kick it off, the framework itself still has to include files left and right. And modules or not, some code somewhere still has to include supporting files. For every single file in your codebase, you will have at least one include call to it somewhere, possibly many more. It's silly to look at this as a "how many includes do you need to launch a request", because any simpleton can make it so that all you see is a single include, but that doesn't stop the fact that you must still manually include each and every other file -- at some point in the framework -- before you can use it. > (1) conceptual; less "WTF" for new developers to deal with I'll point to the supporting evidence provided by others here that shows that pretty much every modern framework uses autoloading. Thus, I wouldn't say it's a WTF, rather, the opposite is probably more true: who manually includes files anymore? > (2) complexity; code-flow is both simpler and more explicit. Removing include calls does not make the code more complex nor harder to follow, any decent IDE will let you control-click into the definition of classes. I'd argue that less LoC is a good thing (so long as we're not talking about "clever code", which this isn't). > If you can provide some demo code, I'd love to see it. Or, you know, you can read what I said as I perfectly explained the situation. But I'll play along. // test 1 $start = microtime(1); $i = 1000; while (--$i); $end = microtime(1) - $start; printf('%.7f', $end); // .00004s die; // test 2 $start = microtime(1); $i = 1000; while (--$i) { require './test.php'; } $end = microtime(1) - $start; printf('%.7f', $end); // .082s Note that test.php was a completely empty file (and thus no parsing required); in reality, those files are often 1000+ lines of code and take much longer to parse. Even with this simple example, the non-require version is 2000x's faster than the require version. This is also in a perfect world, e.g. there's no other files also being required that'd overflow the realpath cache, nor is there really any other OS activity that will hamper my tests. In the wild, there could be 50-100 requests being served concurrently, which would affect the system calls even more. > I think you will find largely it's just a result of having a dumb framework or being ultra-contrived in your example to an unrealistic degree. It's a dumb framework, but considering that it's a legacy project that has survived 10 years of organic growth and is still paying my salary (I've been here less than 1/2 of that time), it's not getting re-written anytime soon. But, weren't we talking about autoloading?