I’m wondering whether a file gets loaded entirely when it contains conditional statements.
Assume I’m having a big file with about 5000 lines of code (just as an example), but half of the code wouldn’t get executed because it’s in a conditional statement. Would it still take the same time to load the file?
I assume not, so can I also assume that it’s generally faster to split code in multiple files and let an autoloader handle the needed files ? Or would the new file request slow the whole thing down again ? In this case: Where’s the border when a file load is faster than the execution of a file with conditional statements?
Answering the first part of the question is simple: yes, files are loaded in their entirety in order to be parsed. It doesn’t matter if half or all of the code will end up being not executed.
The second part is more tricky. You are talking about performance, but this specific area (trying to extract more perf by optimizing the number and size of includes) is pretty high-hanging fruit. Therefore:
Based on experience, I believe you are worrying about something that only affects your bottom line in a negligible manner. Stop doing that and just write good, maintainable code. Splitting your source code as much as you like and using an autoloader is a good approach to doing that.