decentraland / explorer-technical-backlog

This is the backlog for big scale architecture decisions regarding the Explorer product and its sub-products
1 stars 2 forks source link

Centralize time-slicing logic #22

Closed BrianAmadori closed 1 year ago

BrianAmadori commented 3 years ago

Right now, we have a bunch of systems that implement time-slicing. The pattern goes out like this:

const float TIME_BUDGET = 0.016f;
float ongoingTime = 0;

...
// somewhere in a coroutine
...

float elapsedTime = Time.realtimeSinceStartup;

HeavyProcess();

ongoingTime += Time.realtimeSinceStartup - elapsedTime;

if ( ongoingTime > TIME_BUDGET ) 
{
    ongoingTime = 0;
    yield return null;
}

We should centralize this pattern in a common system. If we do this, we have the advantage of making a composite of the time-slicing systems and give them some kind of priority. From this way, we can make the timeBudget really global, and not per system. This would ensure some kind of safety in which we can ensure we don't spend more than the time budget per frame for the systems involved.

We agreed on implementing this system if we need more time-slicing logic down the road, and gradually refactor the existing systems that use this kind of logic.