Can 'every x seconds' harm performance?

Get help using Construct 2

Post » Sun Jan 10, 2016 1:13 pm

I've been adding 'every 1/5' or 'every 1/10' etc. to conditions that need to be updated constantly but not necessarily every single tick, in the hopes that it will improve performance by giving the computer fewer things to think about at once.

However, could it actually be harming performance because it requires lots of timers to be kept track of? :?
B
8
S
1
Posts: 54
Reputation: 824

Post » Sun Jan 10, 2016 1:49 pm

Hey Mortimer, :)

Off hand, I doubt it would harm performance.
If I recall, the "every" condition is tested each tick rather than being triggered by an internal timer.

I don't know for sure, but I would think the way the "every x seconds" condition is handled internally, is that the condition has a single hidden variable that gets incremented by the delta time (time since last tick) each tick. Then, each tick, the condition is tested to see if the total amount of time in that variable exceeds the "every" amount specified.

So multiple "every" conditions would just have the extra variable, increment per tick, and check per tick as overhead, which hopefully shouldn't be that much.

If anyone is more familiar with the inner workings of the "every x seconds" condition, feel free to correct my speculation. :)
B
27
S
18
G
8
Posts: 327
Reputation: 6,154

Post » Sun Jan 10, 2016 2:02 pm

Thanks for responding! I expect you're right. If that's true and if I have an absolute crapload of "every"s, then the computer's got quite a lot of sums to work out every tick... So I wonder if that's any better than just checking all my conditions every tick instead. Ugh.

Anyone know for certain?
B
8
S
1
Posts: 54
Reputation: 824

Post » Sun Jan 10, 2016 3:11 pm

I'm not sure if this will help, but I can share a little of my own experience with optimizing, via the use of "every-x-seconds conditions".

If there is a lot of collision checking going on in a single event, and you can get away with doing it less often than every tick, that's the main place I've actually seen directly visible performance gains.

Though I suspect that pretty much any non-tick-essential event, if it's already eating up a large share of your game's CPU budget, is a good candidate for demotion from per-tick to every-x-seconds.

Example
As a practical example, in ArcherOpterix, the phantoms check to see if they are touching a wall, so they can reverse direction. That check uses an "overlapping at offset" condition. The phantoms move slowly, so I didn't really need it running absolutely every tick. I switched it from every tick to every 0.2 seconds, so the phantoms behaved identically to the naked eye, but the game ran about 2 to 3 times faster.

Now that said, I'm not sure why I wasn't then just getting a minor slowdown every 0.2 seconds. But I didn't. The game ran smoothly. I thought it was a bit weird, since my game should still be running all of the collision checks on a single tick every so often, and in-between there would be a bunch of far less demanding ticks.

So if the work load isn't being spread over multiple frames automatically, and I don't think it is, at least not at the C2-event level, then maybe there's some hapless downstream system that gets backed up if you just pile tons of work onto it, until you start to see that burden manifest as a performance hit.

In hindsight, I could have given each phantom a random group number from 1 to 10, and then just handled one group per tick, round-robin style, to spread out the work load a little. Though the every 0.2 seconds optimization worked so I've left it with that.
B
27
S
18
G
8
Posts: 327
Reputation: 6,154

Post » Mon Jan 11, 2016 1:12 pm

You can answer these questions yourself with measurements, but I really don't think it has any significant impact at all. "Every" events don't create timers that need to be tracked, they work more like a condition that says "the timestamp this event last ran is greater than X seconds", which is basically a simple number comparison, which is the kind of thing it is a waste of time to worry about.
Scirra Founder
B
395
S
232
G
88
Posts: 24,368
Reputation: 193,746

Post » Mon Jan 11, 2016 4:06 pm

Sam Mortimer wrote:I've been adding 'every 1/5' or 'every 1/10' etc. to conditions that need to be updated constantly but not necessarily every single tick, in the hopes that it will improve performance by giving the computer fewer things to think about at once.

However, could it actually be harming performance because it requires lots of timers to be kept track of? :?


Based in my experience, It really does ease up the performance a bit . But it only happens if you use the time interval (0.3 ~ 1.0) but it is really not noticeable if you ask me. It is only based on the difference of working time and free time to give the system a rest. So don't waste your time on that and improve your game-play like ashley said. XD
The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
64
S
18
G
90
Posts: 1,118
Reputation: 59,565

Post » Mon Jan 11, 2016 6:12 pm

thanks lovely people
B
8
S
1
Posts: 54
Reputation: 824


Return to How do I....?

Who is online

Users browsing this forum: blue visionary and 4 guests