Page 1 of 1
performance implications of classes in their own file
Posted: Thu Aug 10, 2006 12:42 am
by Luke
What are the performance implications of putting classes in their own file and having to load as many files as you have classes? Seems like it would be a high cost to performance... am I wrong?
Posted: Thu Aug 10, 2006 1:42 am
by feyd
As I've said before, it can vary quite a bit depending on your particular situation. In general, it is considered a better practice of storing classes in separate files. OOP isn't about performance.
Posted: Thu Aug 10, 2006 1:51 am
by jamiel
There is a performance overhead, but the time you would save with this optimization means you would incur a maintainability cost which is just not worth it. Only when your project is working should you look at the effeciency of your code and refactor as neccessary if something is unacceptably slow.
Posted: Thu Aug 10, 2006 11:48 am
by AKA Panama Jack
There is a performance overhead when using classes no matter what in PHP.
Here is the funny thing...
Loading a bunch of small classes from files is usually faster than loading one large class that has all of the came class functions as the bunch of small classes.
The larger the class the longer it takes to create the object. That is a firm rule for PHP.
Posted: Thu Aug 10, 2006 2:01 pm
by Ambush Commander
Look, if you're doing anything remotely interesting, userspace code execution will usually outweigh parse time.
If the extra performance really is necessary, install an opcode cache or create a utility script that inlines all includes before deployment (not that difficult with PHP's parsing functions). The readability benefit from seperate pages is just too much to trade off for this argument.
Posted: Thu Aug 10, 2006 2:04 pm
by Luke
OK

Posted: Thu Aug 10, 2006 4:48 pm
by AKA Panama Jack
Sure an OpCode cache is a good idea but not every server has something like that. Also, the performance gain when creating a new object isn't that much when using an OpCode cache. It's just the way PHP creates and manages objects.
Creating big class objects with PHP (any version) is going to be slow even using a precompiler. You would be better off creating a group of SMALL class objects as they are needed. The shotgun, large class method is not a good idea with PHP.