Search Unity

High CPU Usage

Discussion in 'Windows' started by riot9, May 6, 2014.

  1. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    Hi everyone. I've made games on XNA before, but this is my first venture into Unity. I'm running into what seems abnormally high CPU usage, and wanted to see if this is normal overhead.

    I'm making a text based adventure, and as such, text scrolling is very important. So I'm implementing kinetic scrolling manually (couldn't really find any plugins that seemed worth the money, but I'd be glad to take suggestions if there are any).

    So really I just have GUI labels in a scrollview that I'm letting the user scroll through. That's it. The problem is that when I run the app on my Windows Phone, my Nexus 7, and my Surface Pro, the devices get hot pretty fast. The Surface Pro CPU usage for that app is between 28% and 35%, when it's doing nothing but draw the text and check for touch input.

    As a sanity check I built a completely blank project, and built it for Win8 with nothing but a camera in it. That too was hovering around a constant 33% CPU usage.

    I know that there is room for optimization in my code, but a blank project running that high seems worrisome to me. I hope I'm doing something wrong.

    I realize that Unity may not be the EASIEST choice for a text game, but I chose it so I could quickly go multiplatform, and to enable me do a 3D game in the future.

    Is this normal? Is this just the overhead of using Unity?

    Thanks in advance!
     
  2. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    Okay, so I HAVE to be doing something wrong, or missing something.

    I just downloaded three different unity games from the Windows Store, and none of them were as bad as mine. Some are in the range of 10% on my Surface, and the worst was 40%, but it was full-on 3D.

    So... Either I'm missing something, or doing something horribly wrong. Just not sure which.

    Any thoughts?
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Sounds like you're using the wrong techniques. Explain how you make text, all the details.
     
  4. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    Thanks for the reply hippocoder.

    I have two implementations I've tried.

    The first is very simple. Update() just looks for new touch input. If it finds one of the different touch types it will either update the scrollview position for drag, or if it was the end of a touch it applies inertia. If it found no touch input, and there's inertia, it will lerp until it's 0.
    The GUI side simply draws the text in a scrollview, based on the position calculated in Update();
    This implementation hovers at 33.3% almost constant with my surface pro 2.

    The second one is exactly the same, except it calculates inertia by tracking the last four deltaY, and delta time. I average those out to make the inertia. I found this works better for me, but the added calculations only increase CPU usage by .7 percent, putting it at 34%.

    The thing that troubles me more is the fact that a completely blank project, with nothing but a camera is running in the 29% range as well. I'm not debugging either. I built it, then ran it using Vistual Studio. Closed it out, then ran it from the programs list.
    I don't have CPU stats from the Windows Phone or Nexus 7, but both get really warm after 30 seconds or so of testing my apps.

    Do I have something in my config wrong?

    I really want to use Unity, so I'm hoping there's something I'm doing wrong. The blank project problem is a little worrisome to me though.

    Thanks again in advance!
     
  5. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
    A guess would be that you have something constantly being fired in the Update(). Do you have multiple objects that are looking for the input? Are you sure the motion is actually being stopped and not just moving really, really slow? I have issues like that were I thought I was ending an action, but it was actually still looping.

    I would start by just debugging your updates, throw some output in them during parts and ensure that they are still doing things you shouldn't. If you have pro, check the profiler. Bear in mind that Update() happens every frame for object that calls it, try to them as stripped down as possible or avoid using Update unless you really need to. It is a great place for performance to leak away.
     
  6. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    Thanks zombiegorilla.

    I don't actually think the code is my real problem now. Like I said, a blank project takes up almost as much CPU. To really prove it though I commented everything out of my start(), update() and onGui(). So no script runs except for variable initialization. It still consumes 25-30% of my CPU, just sitting there, rendering a blue screen.

    Other games in the Windows Store don't seem to have this problem, so I know something has to be wrong on my end, but I have no idea what.

    I'm on Unity 4.3.4f, not pro.

    If someone else using Windows 8 builds a clean project, no objects, assets, scripts, nothing, then builds it, and runs it in VS, I'd love to know if you get this too.

    Thanks again, I really appreciate any input.
     
  7. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    Sorry to keep spamming this thread, but I keep finding more information.

    I just installed Unity and VS 2013 on a separate computer, and I'm getting the same results with a blank project. It's running at 33% with nothing in it but a camera.

    My Surface is on Win 8.1 Update 1, my other computer is on Windows 8.1 (no update 1).

    Can anyone else reproduce these results, or do I happen to have something really wrong on two machines?

    UPDATE:
    I just installed Unity on a vanilla Windows 8 computer and a blank project (again, nothing but a camera) was using 15% of that CPU. That machine is an 8 core AMD though, which does have roughly twice the power of my Surface, or the other laptop I tried it on.
     
    Last edited: May 6, 2014
  8. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    I've just tested my game (Pobble) on Facebook, which is a fairly simple 2D affair, and it sits at around 2-3% CPU usage on my i7 laptop, it would be interesting to compare that with your 8 core AMD PC, there's a link in my signature if you want to try it.

    Sadly I can't offer any useful advice though :(
     
  9. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    Thanks Munchy,

    Your game hovers around 2-3 for me as well, so that seems fine. The Win8 apps I've downloaded so far that use Unity don't seem to have the problem either.

    I'm wondering specifically if there's something going on with Windows 8 (store apps) built using Unity 4.3.4f .
    It seems highly unlikely that it's a problem with Unity, but it's also very odd that I've tried three different computers with similar results.

    Just in case someone is in a position to test, here's exactly what I did:

    Install 4.3.4f fresh (not really expecting anyone to reinstall to test this though, just listing it for accuracy).
    Install VS 2013 (or VS 2012 in the case of the Win8 Vanilla) fresh.
    Open Unity.
    Create a new project.
    Immediately build for Windows Store, targeting Win 8, or 8.1 (depending on the version of the OS I'm running it on).
    Open the resulting file in Visual Studio.
    Change the target platform from ARM to x86.
    Click Local Machine to launch the application.

    On my two haswell i5 processors (surface pro 2, and a dell something or other) the CPU usage is around 30-33%.
    On my 8 core AMD desktop, it is around 14% (but it is about twice as powerful as the other devices, so not surprising).

    Again, sorry for the massive spamming of this thread, but I'm really baffled, and would love any help that could be offered.
     
  10. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    By default I think Unity will update as fast as the system allows it to. You may want to limit the application framerate.
     
    raja1250 likes this.
  11. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    um

    You're talking about %cpu not ms...

    if you draw a single pixel it's likely to take up a large % of the time because it's relative yet still be 0.001ms actual performance loss. Are you looking at the profiler wrong? Worry about ms.

    Percentage is an almost useless stat in the profiler, it's mostly used when you have a complete project to get a quick glance at what areas are most busy.
     
  12. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    I could be wrong, but I believe the percentages riot9 is posting are not from the profiler, but from another program such as the Windows task manager.
     
  13. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    Thanks hippocoder and MakeCodeNow. As a Unity newbie I really appreciate your input.

    I'm not looking in the profiler. I'm looking at the Windows performance. The app is hogging 33% of total available resources. Which explains why my surface starts to get warm after running my app for a minute (and the blank apps as well).

    Although it could be framerate (and I'll put in some code to see what the framerate is later), the apps I downloaded from the windows store that I know use unity ran under 10% system CPU, and they were extremely simplistic. I doubt their developers were concerned with performance, as they were more or less "Hello World" unity apps.

    I downgraded to Unity 4.2, and a blank project seems to use the same amount of system CPU.

    Thanks again!
     
  14. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    This is kind of normal for anything that's not constrained by vsync. Some GPUs get really hot if left to loop hard and fast... It would probably be better for you to test the 2D example project from Unity or such - some form of real world comparison, or just get on with making your game and worry about the optimisation when it actually is slowing down.

    This sort of thing so soon is hard to pinpoint (unless it's running less than 60fps).
     
  15. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    That's right DanielQuick, I don't have Unity Pro yet, I'm still trying to decide if it will be my final solution. So no profiling available to me.

    Is there anyone who is set up in a way that they could try to reproduce my results on a Windows 8 Store app? I would love to be proven wrong, because I'm really liking everything else I'm seeing in Unity.
     
  16. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    My real concern is that I'll be draining batteries with a simple text adventure game. Something like that is going to hurt my reviews when I eventually get it to market. My Windows Phone 8 device, and Nexus 7 both get warm when running my app, or blank apps. I believe I can use Visual Studio to profile the Windows Phone (and I'll do that tonight to confirm what's happening there).

    I know there's got to be something I'm doing wrong, or something I don't understand, since the other simple Unity apps on the store don't have this problem.

    Thanks again hippocoder for continuing to reply.
     
  17. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    Okay, another update.

    I built the same blank project as an .exe, and also as a web app, and both of those take less than 1% of my CPU.

    I'll look more into Windows Phone tonight, but I know something is fundamentally different between an .exe, web app, and Windows 8 Store app.

    Anyone else have Win8 they can try to reproduce this on?


    Maybe this thread should be moved to the Windows Development forum(if that's possible)?
     
    Last edited: May 6, 2014
  18. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Sure I'll move it.
     
  19. seedee3d

    seedee3d

    Joined:
    Mar 30, 2015
    Posts:
    24
    my cpu usage is 100 percent. and everything except unity l_AGZ
     
  20. leewang2502

    leewang2502

    Joined:
    Jan 19, 2015
    Posts:
    8
    Still no resolve it?
    I have the same issue on Blackberry platform
    I build a blank game. It run ok in IOS and Android but in BB, the CPU is too high, always 29% when its in the background
    Is any ideas about this?

    THanks in advance
     
  21. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,678
    Are you by any chance measuring a debug build?
     
  22. JeffreyStrate

    JeffreyStrate

    Joined:
    Jul 27, 2016
    Posts:
    32
    In Notfall

    Klick an projekt

    Baket CGI , Precomputed Realtime CGi /OFF = 0% CPU USAGE / ON 50% Usage 8x CPU