I have a web application written in PHP. It uses MySQL for data storage. Today I decided to profile it to find bottlenecks in code and find which parts of it are running slower that the others. The usual stuff. I did a lot of work and now my page loads in less than 0.05 seconds on my desktop.
But now my profiler tells me that half of this time my app is busy constructing classes. Front
controller requires Config
, Database
and User
classes, they have their own stuff to do in __construct()
, then it loads Page
controller, which loads Cache
and View
, and after that it fires the main()
method of Page
. And all that stuff takes 50% of total working time. And the other 50% are used for querying db, juggling query results and outputting them in View
.
The question is: is this okay? The "50% for construction" thing? Does that mean that I optimized my app well? I've been taught that the most time-consuming operations for web app are database queries. I optimized them, applied some caches, and now they are totally under control. And I actually have no clue on how to optimize class construction. Should I try to optimize these __construct()
methods or leave them be?