proggR Posted November 30, 2011 Share Posted November 30, 2011 I'm curious if anyone has information on how much overhead there is with creating an object in PHP. I've tried finding some benchmarks but haven't really been able to find anything solid to use for reference. Also, when dealing with objects what optimizations can be done to improve performance. I ask because my project I've been working on is entirely OO. Everything, including views, are objects (though their state and behaviour is really just the model they're representing and a show() function that has the HTML used to display the model). This makes development very easy and clean but I'm trying to figure out how much of a difference I can expect in production and in what ways I can limit any negative side effects. What things could be cached, and what things can't? For example, is it possible to cache the class definition without caching instances of that definition (since they'd be different from page view to pageview)? Would that be helpful. Any pointers would be great. I haven't had a lot of time with performance tweaking so I'm not sure of any known pitfalls. I know objects and function calls use a bit more overhead but I've never found out how much more. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/252153-object-overhead/ Share on other sites More sharing options...
xyph Posted November 30, 2011 Share Posted November 30, 2011 It's minor. You're usually slowed by disk access times rather than CPU/memory issues anyways. Generally, using objects adds little overhead, and can actually save memory in certain applications. Quote Link to comment https://forums.phpfreaks.com/topic/252153-object-overhead/#findComment-1292780 Share on other sites More sharing options...
Pandemikk Posted November 30, 2011 Share Posted November 30, 2011 Generally the time saved by having a consistent easy to manage code on the programmer's end is far more than the overhead will ever accumulate to. Unless you're really strapped for resources (in which case your problem is most likely nothing on the PHP side) then you should use OOP. I don't recommend making everything OOP because that would just be too demanding, but it's definitely something you should use for error checking and database interactions. Quote Link to comment https://forums.phpfreaks.com/topic/252153-object-overhead/#findComment-1292782 Share on other sites More sharing options...
xyph Posted December 1, 2011 Share Posted December 1, 2011 What's wrong with using objects to handle output or script interactions? There's no reason you can't develop an entire application using objects. Quote Link to comment https://forums.phpfreaks.com/topic/252153-object-overhead/#findComment-1292848 Share on other sites More sharing options...
proggR Posted December 1, 2011 Author Share Posted December 1, 2011 Good to know. Thanks for the answers. Quote Link to comment https://forums.phpfreaks.com/topic/252153-object-overhead/#findComment-1293206 Share on other sites More sharing options...
Alex Posted December 1, 2011 Share Posted December 1, 2011 There's nothing wrong with making your application entirely OOP. Any performance issues will be with your code, not because of you're using objects. If you have any concerns you can do some tests for yourself. See this useful post by .josh for benchmarking. Quote Link to comment https://forums.phpfreaks.com/topic/252153-object-overhead/#findComment-1293208 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.