How can I do staggered updates?

I have a system that:

  • currently runs on the Update schedule
  • processes a very large amount of entities
  • takes enough time to compute that it is a major performance hook
  • doesn't actually need to run every Update for every entity. It's probably OK if it runs only about every 100 updates per entity, as long as it knows how much time elapsed since the last update for that entity.

Now I could of course run the system on a timer that only updates it once per second, but then I end up with a lag-spike once per second.

What I would like to do is run it every Update, but have each update only process 1% of the entities. Then the next update processes the next 1% and so on. The system of course needs to know the delta_seconds since each batch was processed last. You should also know that the entities processed by the system constantly get added and removed. And while doing that I would prefer if the batches would remain roughly the same size so the frame-time doesn't fluctuate too much.

Any ideas how I can pull that off?

Btw: I am an experienced programmer in general, but I am only dabbling in Rust and Bevy for about 2 weeks.

​

Posted Mar 23, 2024, 2:59 PM UTC

78

Comments aren't archived yet

This post had 8 comments on Reddit. Comments for this period haven't been loaded into the archive yet.