CPU usage question

  • Hi Ashley / anyone else who might be able to help

    I just have a quick question about normal CPU usage.

    Some of the simple examples as well as some of my simple levels go up to about 90% cpu usage on iPhone SE.

    This is info I get from the remote preview profiler.

    I am getting 60 fps, but the CPU usage seems very high.

    Is this normal?

    Thank you in advance

  • Hi Ashley / anyone else who might be able to help

    I just have a quick question about normal CPU usage.

    Some of the simple examples as well as some of my simple levels go up to about 90% cpu usage on iPhone SE.

    This is info I get from the remote preview profiler.

    I am getting 60 fps, but the CPU usage seems very high.

    Is this normal?

    Thank you in advance

    It is easy to max out a mobile CPU with events. I recommend creating a set of event groups called “Test Group 1”, “Test Group 2”, etc. in the event sheet, and then profiling your game. This will tell you exactly which events are taking up what percentage of the CPU, which should allow you to redesign the events to use less CPU time.

  • Yeah, try not using a lot of every tick events and condition checks. Replace everything that can be changed to triggers or trigger once events. If you get 90% cpu usage for a simple game then the game is clearly not optimized.

    Mobile development is a whole other science and is a lot harder than desktop game development. So many new users come to C2 and think that making a mobile game is the easiest way to start when it is in fact by far the hardest. You need to fully understand optimization and how to get as much performance as possible at the lowest cost.

    But there are some useful threads on the forum about it which can be a good start

  • Some things I always do for mobile.

    Groups

    Using groups and closing them when not needed. In case you have a lot of events constantly checking for conditions you can often close whole group of events when they are not needed. Events in these groups don't run at all when closed.

    Functions

    Functions don't run and don't use CPU time unless they are called, so limiting your the amount of top level events can reduce CPU usage a lot. For example.

    Every X seconds.

    A lot of things don't need to be checked and run and updated every tick. (about 60 times per second). You can easily cut CPU time by using every X seconds instead in many cases.

    Is on screen

    If you have big layouts this can be very useful in some cases.

    Pick nearest

    If you're checking distances and collisions etc. this condition can be extremely powerful. If you want to detect if something is within range or is colliding, you only need to check the closest instance. Not every sprite of the same kind in the layout, so this can save you a LOT of cpu time, by limiting the checks to only the closest one. (Works great for pickups, powerups, collision detection etc)

  • Hi guys

    Thanks all for the replies. I am literally not using any 'Every Frame' events, and most of my events are either onTouch or on Animation complete type triggers.

    I really don't know what I can do to optimise the level any further.

    From my tests, some of the simple examples that ship with C3 also use up to 90% cpu - this feels like something is not right.

  • So it looks like most of the high cpu usage in this case is being cause by ...

    ... updating a contdown timer textfield

    It seems strange that something so small and simple would require all this cpu usage.

  • So it looks like most of the high cpu usage in this case is being cause by ...

    ... updating a contdown timer textfield

    It seems strange that something so small and simple would require all this cpu usage.

    Textfields are the worst! It is up to the browser engine to draw the text every time. Consider changing this to every second, or whenever an integer value changes, and consider using a spritefont instead.

  • Thanks for the info on text fields

    I just did a simple test where I use a single behaviour (Sine) to make a single image get smaller and bigger.

    Just using this single behaviour on a single image says it's using around 85% CPU on an iPhone SE.

    This doesn't seem right, but if it is, there is not much that can be done optimisation wise, if your game require some of these behaviours (e.g. sine / tween etc.)

    @Ashley - do you have any thoughts on this, I would like to know whether the reading is perhaps incorrect.

    Thanks guys

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I take care of textfields this way; hide them on a bottom layer and drag outside of layout. Then I use a sprite with number graphics from 0 - 9 ( 10 frames ) to display whatever is in Text1,2,3,4, whatever ( usually timer, score, health pct. ).

    You could do the same with letters, but I find that most text that needs updating uses numbers anyway. I started doing it this way because it looked better, I could use any font and effects I wanted to without making each number anything more than a frame in a simple sprite.

    Seems that also works better as far as optimization goes too.

    The only game I have on the arcade here has a timer done like that: https://www.scirra.com/arcade/sports-ga ... 18939?cp=2

    Not sure about iPhone, but on a 5 year old laptop CPU usage is around 2-3% when playing that game

  • I take care of textfields this way; hide them on a bottom layer and drag outside of layout. Then I use a sprite with number graphics from 0 - 9 ( 10 frames ) to display whatever is in Text1,2,3,4, whatever ( usually timer, score, health pct. ).

    You could do the same with letters, but I find that most text that needs updating uses numbers anyway. I started doing it this way because it looked better, I could use any font and effects I wanted to without making each number anything more than a frame in a simple sprite.

    Seems that also works better as far as optimization goes too.

    The only game I have on the arcade here has a timer done like that: https://www.scirra.com/arcade/sports-ga ... 18939?cp=2

    Not sure about iPhone, but on a 5 year old laptop CPU usage is around 2-3% when playing that game

    But why use a text object at all? You could use a variable or arrays to store the text that should be displayed. Your way seems like a very unlogical way of doing it. Sounds like you should just use spritefonts instead which is exactly what you need without the unnecessary events. It works just like the text object but a lot more optimized. Just set the text with one event and you're good to go.

    The regular text object is mostly used for debugging and should never be used in any form in final builds.

  • My game uses Webfonts, performance is absolutely fine so long as you only set the text once and not every tick.

  • Hi Ashley / others

    Since there is still no official answer, I'll re-ask the question hoping someone might spot it.

    Taking the cpu heavy text fields out of the equation, I've tried setting up a barebones project that is using a single 'sine' behaviour on a single sprite.

    This alone make the cpu go to around 85% on an iPhone SE. This is from reading the remote preview debug info.

    Is this reading correct? If it is than there is not much that can be done to optimise your game, if you rely on some of these behaviours.

  • I’m running my first project on an iPhone 6s+ - I have 3 instances of webfonts (the stand-in logo, the hi-score and current score - both updated every tick) the reset of the app is made up of very simple graphics. My CPU ussageis also around 85/90%.

  • Ninjadoodle - as the manual notes, the reading is a timer-based estimate. There's a lot of stuff that can throw it off. For example if the CPU throttles down in to a low-power mode to save battery, it will take longer to do the same work. This makes the CPU take longer to process a tick, and since our CPU reading is a timer-based estimate, the timer covers more time, and makes for a higher reading. So you can end up with a high CPU reading even when the device is using say 10% capacity, because it's done something like clocked itself down by 10x to save battery.

    This happens a lot, and I've also noticed it in C3's GPU measurements too. If you run a benchmark the measurements will steadily increase towards close to the 100% mark, then suddenly jump way down as the workload gets more intense. The device didn't suddenly have less work to do - it's always been increasing - it probably just jumped up to a higher performance mode to compensate for the workload. We can't access the CPU/GPU usage directly in a browser, so we have to estimate it from timers, and this is one of the drawbacks of timer-based measurement: we really measure "how long did the work take" rather than the more accurate "what proportion of capacity is being used".

    I made a quick demo and ran it on an iPad Air 2 with iOS 11. It does start at around 83% CPU. However if you touch the screen a bit, the CPU drops down to ~10%. This is probably because it starts in a low-power mode doing work slowly to save battery, but when you interact with it then iOS boosts the priority of the app, powers up the CPU, which does the work faster, so a shorter time is measured, so the engine's CPU measurement drops down.

    So yes, it's normal. It's not really using up all your CPU, it's just saving battery. Since we have to use timer-based measurements, you will only get reliable measurements when driving the device to its highest performance tier.

  • Hi Ashley

    Thank you very much for the detailed answer, I appreciate you taking the time to do this.

    I understand the issues you've described, but can't help feeling that the 'cpu usage reading' is not much use, when it is so strongly affected by other factors.

    I was worried that a lot of the behaviours were really that cpu hungry, but was confused as my game still ran 60fps.

    Thanks again!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)