Welcome Guest, Not a member yet? Register   Sign In
More controllers good for modularity, bad for performance?
#1

Of course it's nice to have different classes/controllers performing specific tasks e.g. email, login etc.

But it also means I will have to load these controllers whenever I need to use them. Every time I do that they are being instantiated which is bad for performance.

So I guess my best bet would be to load them in specific methods that require them instead of the constructor?

PS. Im also very reluctant to autoload things, for now I just have session library there and I would rather load them in specific classes/methods.
Do the one thing you think you cannot do. Fail at it. Try again. Do better the second time. The only people who never tumble are those who never mount the high wire.
Reply
#2

Optimally breaking requirements down into classes and controllers is part art and part science. Robert Martin (aka "Uncle Bob") is a renowned software developer that writes and talks a lot about objection orientation. You can find some of his videos on YouTube. But he doesn't address CodeIgniter specifically.

Your best bet may be to load them in methods that require them, but will you call those methods more than once? CI won't load them twice, but it will take some number of microseconds to decide not to. Smile

I also don't autoload anything.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply
#3

Not autoloading is a good thing for performance.

For separating things into more organized classes that each deal with a single topic - yes! do it. While there might be some minimal impact on performance, it won't amount to anything real-world. Your database queries will hurt your performance before your number of classes will 9 times out of 10. And for those other times, there's always caching which is simple to do in CI.

It's better in this case to take the small performance hit and maintain the ease of development, IMHO.
Reply
#4

@RobertSF and kilishan: Thank you!
Do the one thing you think you cannot do. Fail at it. Try again. Do better the second time. The only people who never tumble are those who never mount the high wire.
Reply
#5

Make your contrlollers to load only when needed. Coz loading all of them at the same time will decrease the performance.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB