Can 'every x seconds' harm performance?

0 favourites
  • 7 posts
From the Asset Store
This is a Dungeon Master tool & the 1st of 12 Combat Engines from the Building Combat Engines for Browser Games workshop
  • 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?

  • 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.

  • 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?

  • 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.

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

  • thanks lovely people

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