Why I can't not optimize.

Posted on July 29, 2012 | 3 minute read

A while ago I listened to a talk by Jonathan Blow that covered optimization and talked about how most people worry about it too early and how they should just focus on making things work. I know there was much more said in this talk (it’s long and very interesting), but this is the general message that has stuck with me after listening to it - possibly because many other people already express the same opinions on optimization. It makes sense, but to be honest I’ve been on the fence about following it without question myself.

A disclaimer. I’m no expert, so what I think isn’t really relevant or important to anyone (and if you have been reading my posts and thinking otherwise, stop it). The only person it is important to, in fact, is me, and that’s pretty fricking important considering I’m the one sitting here for hours on end after a day of client work trying to learn this stuff.

So back to optimizing code. My only experience in coding games thus far has been with JavaScript browser games. I did have a PHP stint a while back, but let’s just forget that ever happened. The problem I found with not worrying about optimization at all is that pretty soon I’m stuck with a big mess of code that runs between 50-60fps one second and comes to a screeching 15fps halt the next. And all these little functions and entity checks and collisions and spawns that don’t seem to use up much in terms of resources kind of do when they’re all together and running at the same time like rusty cogs in this huge machine. And it gets to the stage where just moving one function to a more appropriate spot in the code makes a visible difference.

I also like to keep my code relatively clean, and sometimes I’ll spend an hour or so just going through and fixing up spacing, commenting, uncommenting, renaming variables, etc. It’s not just that I enjoy the process in general (it’s kind of relaxing when your brain is cramping from trying to make a new feature work), but it helps me review what I’ve done, make sure I understand it, and commit it to memory.

And maybe leaving that kind of thing until later stages is ok in theory, but if I leave it and just keep going, as someone who’s not an expert with this stuff, I’ll make more clumsy mistakes that slow things down further. And then I’m left with this bundle of bad, bad, performance-crippling crap. So personally, the only way I can manage to make this huge thing run relatively well in different browsers is by polishing the little rusty parts while they’re still fresh in my mind, before they get worse and worse and explode and everyone dies.

I think the “don’t optimize” advice is probably great for people who already kind of know what they’re doing. But for people who are totally new at this and teaching themselves, “optimization” likely means fixing up things that would already be taken into account naturally by a professional programmer. To them, it’s probably not even optimization - it’s just doing things right.




Categories:game dev dev games
comments powered by Disqus