Layers and performance hits

Discussion and feedback on Construct 2

Post » Mon May 12, 2014 11:39 pm

Hey everyone,

It seems, that increased layer numbers in projects increases the load on the cpu while running the game. I made a test in which I compared the same game but where one instance had many layers and one did not (3 compared to 15).

I have generally used layers to help me organize objects. This results in no more than a few extra layers. But now I am working on a large project and need many layers. Even though they are not doing anything as far as I can tell it is still increasing cpu usage (3layers @ 25% cpu)(15layers @ 65% cpu) intel i5.

anyone have some tips or insight when dealing with layers?

It would be nice to have organizational layers that do not have any effect on how construct2 runs - it would only be an editor thing.
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,163

Post » Mon May 12, 2014 11:53 pm

It definitely has a performance hit, so use only as much as you absolutely NEED. Just ask yourself whether its a NEED or a WANT feature when you optimize your game. If its a WANT, is there a way to achieve a similar outcome/result with less work for the CPU? If so, do it. If not, make a call whether its important enough to stay.

Trim the fat so to speak.

I only have layers I need in my games, its never used for organizing objects because that's what the Z sorting command and spawning timing is for. My max layers is 6.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,616

Post » Tue May 13, 2014 1:44 am

12 extra layers should absolutely not cause a 40% increase in CPU use, especially on an i5. My game has somewhere around 20 layers and when running on an old amd Athlon 4400+, the CPU low point is around 35%, and that's also running the thousands of events in the event sheet at the same time (not all the events are running each tick, of course).

I'm not sure what's causing it, though. Are you using layer effects? Forcing the layers to have their own texture? Try making a copy of your capx and experiment, delete everything except the layers, try deactivating all the events, turning all the layer's settings back to their defaults, etc.
Moderator
B
95
S
34
G
33
Posts: 3,007
Reputation: 27,876

Post » Tue May 13, 2014 3:36 am

@Arima Good point, using a WebGL shader effect on a layer is extremely taxing. In my test, just one one layer using an effect with a static sprite cuts performance in half on mobiles.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,616

Post » Tue May 13, 2014 12:14 pm

Using layers has almost zero performance overhead, unless:

- you set 'force own texture' to 'yes'
- you set opacity to something other than 100 (which forces its own texture)
- you set a blend mode other than 'normal' (which forces its own texture)
- you apply any shader effects (which forces its own texture)

In other words, a layer with default settings has no overhead, but will use an entire offscreen texture and have to render via that every frame if you change any of the above rendering settings.
Scirra Founder
B
399
S
236
G
89
Posts: 24,530
Reputation: 195,402

Post » Tue May 13, 2014 12:21 pm

@Ashley - Just so I know, if you have a layer transparency set to say 50%, but then have that invisible, will that cause a performance hit?

I have done this as I have invisible boxes as collision, but want them transparent so I can line them up perfectly in layout view.
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
82
S
14
G
7
Posts: 975
Reputation: 11,037

Post » Tue May 13, 2014 12:22 pm

Invisible layers are not rendered at all, so have no performance impact regardless of their other settings.
Scirra Founder
B
399
S
236
G
89
Posts: 24,530
Reputation: 195,402

Post » Tue May 13, 2014 8:06 pm

@Ashley Thanks for the info - That all makes sense. if you are rotating layers/layout does that make a difference?

@Silverforce - I suppose you are right. I have a lot of wants wrapped up in how I chose to layer my game. Thanks.

@Arima - I am running multiple force to own texture layers. (do different blend modes affect a layer the same way as a webgl effect in terms of cpu usage?

This is my current layer list, it is running fine so far. I think my computer was performing poorly when I was doing some stress tests. I am running the following on an i5 with 25-40% cpu usage. This includes calculating physics as well:

layout effects + post processing including scaling and rotating

GUi
light effects (screen, dodge, or other effects used)
BackGround (destination over)
Climate effects
Liquid (using various shaders)
Foreground parallax
Light effects and illumination (multiply/forces own texture)
Explosions, fire, lasers, and other nonsense (additive blend mode)
Tilelayer (foreground)
TileLayer (active)
TileLaye (background)
Background parallax 1
BGP 2
BGP 3
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,163

Post » Tue May 13, 2014 9:08 pm

I don't know. The easiest way to find out would be to make a test .capx that replicates the layer setup only, and check the CPU use with each part on or off.
Moderator
B
95
S
34
G
33
Posts: 3,007
Reputation: 27,876


Return to Construct 2 General

Who is online

Users browsing this forum: blackhornet and 7 guests