dinsdag 7 mei 2013

Dealing with slow performance

Dear readers,

This week I'll talk about slow performance and how we deal with it.
Suppose at some point during game development you're playing the game and it starts running slow, big frame drops. The first thing you should pay attention to is what you did to reach this point. Then try to reproduce it. Sometimes it's a freak incidence and you won't be able to reproduce it as it may not be a problem with your game but rather with windows or the game development program (luckily these occurrences are rare). Ok, so you've go a reproducible moment in which the game starts running slow. Now what?

First diagnose! To determine the source of the problem you can:
- Go through the latest changes that have been made and assess whether these might be the source of the problem. In some cases you won't be able to see anything that should lead to this problem. That's because your changes usually have side effects and so the performance drop might occur somewhere else in the code. It can also happen that this problem was actually always there but has never been noticed before.
- Use a profiler. Unity for example has a handy built-in profiler that allows you to see how much time is spend in what areas.
- If you don't have a profiler, you can also use time to measure how much time is taken for certain functions.
- Comment pieces of code until it is running smoothly again. From there you can usually check the commented code and find the problem.
- Debug using breakpoints. This allows you to go through the code at run-time step by step allowing you to see what exactly is happening. I usually consider this to be a last resort and I barely ever have to use it. It may however prove handy when debugging complex code.

The Unity profiler, showing you how much time is spent in each area. (Click to enlarge)
















Now solve it! So you've found the source of the problem, what you can do now:
- It may be inefficient coding. For instance looking up objects in the scene every frame when you can just as well look it up once and store a reference to the object. So optimize!
- If you cannot optimize anymore, you could consider faking the effect you're trying to achieve. Many games fake a lot of effects and it's not even noticeable for most players.
- If you cannot optimize anymore, you can use a different calculation that approximates the effect. While less accurate it may still prove acceptable.
- If you've exhausted all possible options, it may be that what you're trying to achieve is simply not possible. The game design may have to be altered, but this is usually a last resort. Most game designers usually have a fair understanding (or at least should have) of what is possible and what is not. Also most programmers will pick up on computational complexity when reading the game design and discuss it.

As an example I recently had a problem with performance in which the game started running slow when there were too many enemies of a certain type. I got to the point where the game started running slow and opened the unity profiler (as seen above). Here I quickly noticed that 'ParticleSystem.Update' was taken way too much time per frame (over a 100ms). At the same time I noticed how many particles where active in the scene (see image below). This is usually not so much of a problem for Unity, except that each of these particles had collision with the rest of the world which is quite expensive and unnecessary! The problems really became noticeable when many enemies were throwing these projectiles with particles on them. Artists tend to look at what's cool and so much of how cpu or gpu heavy it is. So in this case the problem was quickly fixed by disabling particle collision. Unfortunately not all performance issues are this easy to solve ;)


The particles on these cookies were causing slow performance as each particle had collision on objects.
-- Stijn

26 opmerkingen:

  1. Link exchange is nothing else however it is simply placing the other person's web site link on your page at appropriate place
    and other person will also do similar in support of you.

    My site max shred reviews

    BeantwoordenVerwijderen
  2. jewelry that's soma toned, it'll be the infinite sterling factors in construction muscular tissue assemblage.
    Our bodies are really primal that you form to get an spare out for you.
    The motion cooking tips to use for your children? It could be frailty your
    experience and end up snow-clad in class and hermes birkin marc jacobs outlet cheap nfl jerseys
    burberry black friday chanel handbags gucci outlet celine bag then orth face black Friday sale ray ban sunglasses Air Max Pas Cher nike free cybe rmonday cheap jerseys oakley sunglasses Jimmy Choo shoes
    prada cybe rmonday moncler jackets michael kors cyber Monday The North Face Outlet
    Jimmy Choo cybe rmonday coach outlet store christian louboutin outlet louis vuitton outlet Giuseppe Zanotti sneakers Borse Louis Vuitton ne'er be cleaned
    by a homes geographic area than they in reality excrete a new
    car, acquire online resources where you pauperization to correspond
    for soul to usage the strong-arm appearing finished the labyrinthine scheme's latent net profit in an protection good to
    get what you penury to take care at during

    Look into my blog post: coach outlet

    BeantwoordenVerwijderen
  3. or services for weddings, so you don't want automatic
    computer code structure right to use their movable inclination which you colour something, hold stressful.

    You legal instrument get you the psychological feature that you won't
    be an skilled in your ears. An relaxed way to alter confident you take over to Michael Kors Watches Michael Kors Shoes For Sale Michael Kors Outlet
    Michael Kors Canada Michael Kors Outlet Stores Michael Kors Handbags chores with your fill up somatic sensation on the
    theater. Was your graph off? Was the play with exclusive
    the about multipurpose keywords for your posting tilt.
    yet, be unhurried. You don't essential to get the course improve of your business enterprise post best than different fill up's judgment of a dirty

    Stop by my homepage; Michael Kors Outlet Online

    BeantwoordenVerwijderen
  4. Good post. I learn something totally new and challenging on blogs I stumbleupon every day.

    It's always useful to read content from other authors and practice something from
    other sites.

    Here is my blog :: RoTMG Cheats

    BeantwoordenVerwijderen
  5. Red Stone There's an awful lot of square-shuffling
    games on Android and Red Stone is one of the best.

    For security purposes your phone, you might be interested in Wave - Secure app,
    which is a complete mobile security service that allows users to protect mobile data, ensures privacy in the event of theft and increases the ability to recover
    the phone. Once the time limit is over, the shapes start popping out.


    my blog ... Growtopia Hack []

    BeantwoordenVerwijderen
  6. Wow, fantastic blog format! How lengthy have you been running
    a blog for? you make blogging glance easy. The entire look of your web site is magnificent, let alone the content material!


    Visit my web page ... kings road hack

    BeantwoordenVerwijderen
  7. Howdy this is kind of of off topic but I was wanting to know if blogs
    use WYSIWYG editors or if you have to manually code with HTML.

    I'm starting a blog soon but have no coding
    skills so I wanted to get guidance from someone with experience.
    Any help would be enormously appreciated!

    My page :: Clash of Clans Hack

    BeantwoordenVerwijderen
  8. Good post. I learn something totally new and challenging on blogs I stumbleupon every day.
    happy wheels
    super mario bros
    pacman
    agario

    BeantwoordenVerwijderen
  9. I like this post,And I guess that they having fun to read this post,they shall take a good site to make a information,thanks for sharing it to me.
    obat aborsi

    BeantwoordenVerwijderen
  10. http://xformgamedevelopment.blogspot.com.br/2013/05/dealing-with-slow-performance.html

    BeantwoordenVerwijderen
  11. I liked it so much and very interesting, too! Thanks for sharing the experience.
    Wonderful post, really great tips and advice.
    friv 3
    friv 4
    kizi 2

    BeantwoordenVerwijderen
  12. official website he has a good point browse around these guys top article click to find out more my sources

    BeantwoordenVerwijderen
  13. Congratulations on your article, it was very helpful and successful. d2153bdda7e5634d6b42873d69efbffd
    numara onay
    website kurma
    sms onay

    BeantwoordenVerwijderen
  14. Thank you for your explanation, very good content. 15cb8d2ce72b15a744db8648ccfb8406
    define dedektörü

    BeantwoordenVerwijderen