php – Does calling dozens of classes in a system noticeably influence the performance of the application?

Question:

I'm starting to work with object-oriented in PHP and would like to know if the number of classes in a system can interfere with its performance or if there would have to be hundreds of these classes for the performance to really start to be affected.

Answer:

Speaking more of the same, it makes no difference. The explanation is in the other answers.

A practical point to be aware of is how these classes are loaded.

You will probably want to use an autoloader. Then yes, in this case it will consume processes that greatly influence performance.

An autloader consists of including a file when invoking a class that is not present in the script body. This process of including the file consumes a lot of memory and processing.

To reduce this cost, we recommend creating build cache structures. We can also opt or reinforce with cache libraries like Memcache, APC, Opcode, among others.

However, if the concern is whether using OOP classes or concepts will make the system less performant than writing procedural-style code, obviously procedural-style is much faster. However, think of it this way, you need to go from your house to the bar on the corner which is 20 meters away. How will you go?

1. a pé
2. de moto
3. de lamborguini

I will believe you opted for option 1.

Now, let's say you want to go from your house to Paris.

1. a pé e segue nadando pelo oceano
2. de moto e segue de barco a remo pelo oceano
3. vai até um aeroporto e segue de avião

I think you opted for the plane.

But why airplane consumes so much more resources and is it heavy? Isn't it even okay to walk and swim across the ocean? After all, it gives the same result.

Think of this analogy or similar analogies and you will understand when to use a style or conceptY.

Always think about the ultimate goal. What cost/benefit will option X or Y generate?

Having analyzed the cost/benefit, think about the effectiveness.

Is the cost/benefit effective?

These are basic steps to make a better choice.

Scroll to Top