Is there much overhead to including long function collection in PHP?
Suppose I have a very long file, utilities.php, which contains most if not all functions used by the web application. Every single page loaded will include() this file, but utilize maybe just a handful of the functions in it.
Are there any significant downsides to doing things this way, performance wise? I could split the file into several based on the type of functionality provided, but strictly from p开发者_如何学JAVAerformance perspective, is it bad to include everything into every page, but run only what is needed?
To be honest, I'd be more concerned about the maintainability of your code than the size of the file. (If you think the code base will be easier to maintain if it's broken into smaller files based on functionality, then it would be wise do this.)
Irrespective, it's largely irrelevant in the grand scheme of things, as the underlying operating system will most likely be caching such frequently used files in memory, etc.
Additionally, being realistic, if the file becomes so large that it's causing a performance issue, then you're likely to have a much more pressing code maintenance (in terms of managing a file filed with so many functions) problem, at which point it would probably make sense to break the functions into related chunks in their own files.
However, there's most likely to be no need to do this anytime soon - and if you notice any slowdown in the future, I'd recommend using a profiling tool (such as Xdebug) to pinpoint the issue, rather than attempting to second-guess what the problem might be.
Since PHP doesn't use a JIT approach it'll compile your script first to bytecode, which could take a little time if your script is very big. However, when using an optcode cache like APC or XCache it only matters for the first hit. As subsequent hits after that use the already cached bytecode version.
Nope, it doesn't matter.
When it come to real performance question, you will have a solution at your disposal.
精彩评论