Doing stuff is always more expensive than doing nothing

I sometimes get performance questions that go something like "I want to frobnicate my kaboodle, and am considering doing this by flibitzing the wazoo, but I'm worried this might be too expensive".

The only way I know to answer such a question is, mu.

The problem is the phrase "too expensive". It is impossible to judge this without knowing what your limit is, ie. how rich you are. Any time you make a program do more work, that will cost time and usually also memory, but it would be silly to conclude we should do nothing at all! A game that does nothing may run infinitely fast, but it will not be very interesting to play.

Food costs money, but we must eat to survive. Sometimes I eat cheap food; other times I spend more to buy something more delicious. I recently ate at the Herbfarm for my wife Tracy's birthday. That was NOT cheap, certainly not something I could afford to do every day, and I will probably never go back, but it was a fantastic and memorable experience, totally worth it to celebrate a special occasion with special company.

Games are kinda like birthdays: good ones aim to be fantastic, memorable, special, exciting. That's hard to achieve if you're overly focused on saving a few bucks by getting takeout.

With game performance, unlike real life, there is no point trying to save wealth for a rainy day. When your goal is to run at a silky smooth 30 or 60 fps, that means you have either 33 or 16 milliseconds to complete each Update and Draw cycle. If you take longer you get a framerate glitch, but any time you take less, you just wasted some oomph that could have gone into making your game more exciting. It's not like you can save up leftover CPU cycles by spending just 5 milliseconds per tick, then cash in your 401k and spend it all at once when you hit retirement!

Note: the above is only true if you ignore battery life, which can be a reason for phone games to deliberately leave some processing time unused.

When trying to decide if you can afford to flibitz the wazoo, I would start by asking:

  • Can you afford to do this extra work and still meet your framerate goals?  This depends on how much other work your game is already doing, ie. how much performance headroom you have. If you aren't sure, now would be a good time to find out. If you have enough headroom, stop worrying and just go do it already!

  • Can you afford NOT to do this extra work?  If you cut the feature, will your game still be fabulous and spectacular?

  • If you cannot afford to do the work, but also cannot afford not to do it, then welcome to game development :-)  You now have two choices:
    • Apply lateral thinking to find a cheaper way to achieve the same result
    • Find ways to speed up or take out other less important work, thus winning back performance headroom which can be used to implement the new feature

Given a fixed amount of CPU cycles, the trick is not to avoid spending them, but to make sure you spend them wisely on things that will provide maximum bang for buck. Get this right, and gamers will be amazed by the stupendous awesomeness that ensues. Get it wrong, and they will think "meh, boring". This is more of an art than a science, but game developers must develop good instincts about which things are worth investing in.

Comments (10)

  1. filc says:

    i have two comments.

    1) You have more than 33/16ms these days, coz if you are developing AAA title for PC/X360/ps3, you have more cpu cores/spu units/shader units. 🙂

    2) Every ms counts, really, i repeat, every ms counts. Especially if you are doing something on X360 or PS3. So in 99% we ended up in cutting out features somewhere to make our game faster. Why? Well there are TCRs and you must fulfil them otherwise Microsoft or Sony wont let you release the game.

  2. WazooExpert says:

    Thank you for this post – you have just took me out of the loop of analysis of non-existent problem I was so much focused on that I forgot to write a slightest bit of code actually

  3. Me says:

    Good article with a simple point.  Sometimes the obvious thinking is overlooked.  Thanks!

  4. Michael Hansen says:

    I wood shawn is right , it all about where you use the power and when

    you see my render is fast as hell , but the ocean is slow as hell

    so it is a balance of what we can do

    that why i devide into 3 components

    1 ocean

    2 light and shadow

    3 sky and clouds

    so it is up to the user on what to use , as i wood say the xna framework is designs so well that there is not need and real games engine , example if your engine supports 100 different stuff, and the user is going to create a game with your engine that only use 10%

    there we have the problem

    it is better to develop small components that othere can use, and it will ease the pain of game development

    thanks for a nice quality blog post and guide lines as allways



  5. Fish says:

    @filc: You are saying you can stretch time? 33ms or 16ms is that amount of time regardless of how many 'things' you have doing 'stuff'. It may make it easier with more 'things' to do more 'stuff', but you'll still only have that ms budget if you want 30fps or 60fps.

  6. filc says:

    Parallel programming fish. You can do one task on one cpu for 33/16 ms or 2 tasks on 2 cpu's at the same time. And if you are smart enough and have some very nice parallel design in your application then 33/16ms is a life time. 🙂

  7. ShawnHargreaves says:

    I think Fish's point was that parallel processing doesn't give you more time, just the ability to do more work in the same amount of time.

    This is the same thing as in project scheduling, when you have to choose between one developer working for a year or twelve developers working for a month each. Sometimes those two options are fungible, other times not. If your project is date driven (which realtime games all are) then the two are radically different: you can adjust how much work can be accomplished in response to changing levels of parallelization, but cannot move the ship date.

  8. filc says:

    shawn:I think Fish's point was that parallel processing doesn't give you more time, just the ability to do more work in the same amount of time.

    Yes, that's one way how you can look at it, but don't forget if you do more work on more cpu's at the same time and then count a sum how much time did you spend on those tasks, it will be probably (almost definitely) more than 33/16 ms. So the only limitation is that one atomic task can't be longer then 33/16m and it has nothing to do with update or draw cycle in parallel application. And that was my point.

  9. Fish says:

    @filc: Back in the 80's when I was writing Spectrum games I had a whopping 3.54 Mhz of raw z80 power. I had 20ms (PAL) to do everything if I wanted 50fps (which was as rare as hens teeth to be honest). Now, my laptop with its vastly greater CPU speed will happily run a Spectrum emulator and all these games at full speed, along with all the other tasks it is performing, but 20ms is still 20ms. I accept your parallel processing argument, but to run at 60fps you still have to complete everything you need in, regardless of how many CPU's / GPU's you have helping you in your cause. So 16.x ms is still 16.x ms, you just have vast amounts of processing power now to do more 'stuff' in that short amount of time.

  10. Michael Hansen says:

    you see you can only runs as fast as the netframework runs on xbox360 and windows phone 7

    on xbox360 in 3.1 it use 60% of the time and are thread lock in the curent chain of thread that are running so you can not do multithread – only one thread are running in the curent time but the gpu runs faster that the netframework so you can process more on the gpu and the cpu will cacth up later

    device.present flips in xna 3.1 at 2.7 millisecond and it is the time that the cpu has to cacth up with gpu

    on xna 4.0 the device flips at 8.3 milisecond

    so this give the cpu more time to cacth up and pehaps more cores are now in use, so we can move more workload onto the cpu

    that meens that if you are doing physics and havy math stuff , you can do a little more

    this does not effect the overall proformance , becourse it is still under a 25 frames  limit, this is how lov we can go on smoot rendering if you create a small taskmanager that controls you render stuff and game logic

    on the phone 7 i do not now yet, but it think if it is lock at 30 frame per.second , max frame that are in the phone is about 300 to 400

    and the phone must special design for the netframework

    wicth is not the case for the xbox360 wicth runs a top/down execute

    so the overal proformance is verry good on both platforms

    and i like the slow device.present on xbox360

    wicth give my render just the time to do the ocean wicth runs 100% on the gpu/no triangles,only 2 foam maps wicth size 64×64 pixels and one vector4 light value is parsed down to the shader

    that way we can have more time on the gpu to precess all the pixels

    Thanks Shawn and the xna team

Skip to main content