There are two rules which apply when thinking about optimization:
- Do not optimize
- No really, do not optimize
Why optimization is a waste of timeThe reason for that is very simple: Most of the time you spend to much time on a topic which might be solved with a little money on extra hardware. Even worse, you may mess with your system architecture or produce code smell trying to sequeeze some extra milliseconds. Thereby you may introduce bugs, make it maybe harder to test the application or make it harder to understand/debug. All this is happening in the name of optimization in an era where we simply add some more ram or cpu power to our servers or another server to our cluster.
That said, don't be misguided by the simplicity the statement implies. Of course there are times when you need to optimize. When your web page takes 20 seconds to load there might be a problem which cannot be solved with adding more resources but with solving the underlying errors.
On the other hand, trying to make your website load faster when it loads on an average of 50ms might be a bit of the ground.
When you really really have to, stick to some simple rules:
- Make sure you know exactly what to optimize (like: Maximum 1 sec. average loading time of webpage).
- Stop when you achieved your goal. Don't go further until you really need it.
- Aquire knowledge about where to start and really think everything through. Maybe the little bit extra performance can be achieved with simple methods.