performance implications of classes in their own file
Moderator: General Moderators
performance implications of classes in their own file
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?
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
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.
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.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
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.
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.
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
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.
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.