Blog Entry
1 size does not fits all
March 15, 2007 by admin, under Wireless Space.
When it comes to code optimization, there are 2 major categories
1) Optimization for speed
2) Optimzation for memory
When to use which category will depend on your game. If you are creating a turn based game, then obviously optimizing for speed will not be that important unless there is a real noticable drop in the game speed. But if you are creating a real time arcade game, then obviously you need to place a lot of emphasis on optimizing for speed.
Contrary to popular belief, not all optimization should not be left at the end of the project. Some code optimzation can be done during the midst of production as and when needed. For example, during production. I have to declare an if-else loop like this
if (x == 1)
{
//do something
}
I can immediately optimize it with this
switch(x)
{
case 1:
//do something
break;
}
The reason why I use the switch-case instead of the if-else is because at the bytecode level. A switch-case will produce less bytecode than an if-else statement and the less bytecode produced. The better the news since less bytecode == less memory used and also == faster processing.
There are other types of optimization techniques and some have trades off where you can increase the speed, but use up more heap memory etc etc. So you have to decide when is sacrificing speed for memory is good or vice versa.
When it comes to optimization, it pays to adopt a flexible attitude since each project is different and each will require a different amount of speed optimization or memory optimization. Remember, as Sima Yi once said “Flexibility is the key to success”.