Recently optimizations have been my priority, that and the story of the game.
When to optimize
Some people optimize designs and code once they run into problems. This is probably the most efficient way of doing it, you make something and then you fix it. The problem is that you might be propagating the same issue in more than one place. If you are using let’s say 3 variables for every object, whenever you are creating more objects you are initializing these variables, and then when you have to change everything you’ll be working days on only this thing….or at least I did. Why? Because I was stupid enough to add to almost every interactable object on average 3 strings, 3 pieces of text the character would say about the said object.
So my code was something like this: whenever the player would tap on an object, that object’s Text_01 variable would get assigned, as well as Text_02 and Text_03. The character would then do a random between these 3 and spit out something, either Text_01, 02 or 03. On every tap. So if the player would tap through 100 objects, at least 300 strings would be initialized, for what? For Sparta! … I mean for nothing.
Piling up mistakes
So now I’m sitting on my fucking ass writing this post because I’m bored, tired and considering several 200mg ibuprofen to make me happy while going through 100 objects and modifying the code.
I realized it COULD cause problems on some crap devices so I scrapped the initialization of 3 strings for each object, now when the player taps on an object 3 generic public strings get the value of what used to be ObjectTapped_Text_01, 02 and 03. So instead of 300 strings, I only store 3.
A big fucking difference ain’t it? Yes and no; these barely use up memory, I mean it’s just a bloody string, bleh.
However if you just start piling up bullshit like this you might get some bad reviews from people running a rooted Galaxy S1 that complain about the performance, and then as a great dev that you are you will tell them to fuck off and get a decent phone.
Well….they should actually do that, but don’t make yourself look like a prick will ya?
P.S. My project is at around 10%, using 300 strings each having ~ 20 characters would mean that each string would use in average 400 bytes. If my project at 10% has ~ 300 strings that means 0.11 megabytes of memory. At 100% it would be 1.1; and all I did was replace those with placeholders and 3 generic strings which I reuse, so I saved up 1.1 MB in the end. That’s still pretty low but if I were to skip every little thing it would be noticeable on a low end device.