CPU usage question

Post » Fri Oct 20, 2017 1:54 am

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 :)
B
48
S
23
G
9
Posts: 151
Reputation: 9,293

Post » Fri Oct 20, 2017 8:06 am

Ninjadoodle wrote: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.
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
58
S
22
G
26
Posts: 454
Reputation: 18,738

Post » Fri Oct 20, 2017 8:30 am

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 :)
B
61
S
26
G
16
Posts: 802
Reputation: 14,495

Post » Fri Oct 20, 2017 8:48 am

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)
Follow my progress on Twitter
or in this thread Archer Devlog
B
44
S
20
G
19
Posts: 1,091
Reputation: 14,376

Post » Fri Oct 20, 2017 9:08 am

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.
B
48
S
23
G
9
Posts: 151
Reputation: 9,293

Post » Fri Oct 20, 2017 10:38 am

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.
B
48
S
23
G
9
Posts: 151
Reputation: 9,293

Post » Fri Oct 20, 2017 11:02 am

Ninjadoodle wrote: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.
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
58
S
22
G
26
Posts: 454
Reputation: 18,738

Post » Sat Oct 21, 2017 4:05 am

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 :)
B
48
S
23
G
9
Posts: 151
Reputation: 9,293

Post » Sat Oct 21, 2017 12:10 pm

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
B
32
S
14
G
2
Posts: 76
Reputation: 3,502

Post » Sat Oct 21, 2017 10:09 pm

BadMario wrote: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.
B
61
S
26
G
16
Posts: 802
Reputation: 14,495

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests