Core · interface

StepBudgetOptions

Spending a slice of a frame on work that can stop, without spending more than the slice.

Explained in The loop.

interface StepBudgetOptions
import type { StepBudgetOptions } from '@driftengine/core';

In depth

A budgeted step pump: the caller has some job — building a square of world, uploading a mesh, decoding a model — that can be broken into indivisible units, and wants to advance it a little every frame without the frame noticing. This holds the clock and the arithmetic; the caller holds the work and decides what to do next.

What it guarantees, in the honest words: a call costs the larger of the budget and one uninterrupted stop. Not the budget. A stop cannot be interrupted from outside, so the only way to bound a call by the budget alone would be to bound every stop, which is the caller's job and not this one's — see worstIn, which exists to say which of the caller's units is the one over the line.

Why this rather than a count of units. A count bounds the cheap term and leaves the expensive one free. assets/uploadBudget.ts records the measurement that established it: the parts of a model cost between 6 and 254 ms each, so three per frame was three of whatever they happened to be. The clock is exact, needs no per-asset tuning, and is as right on a phone as on a workstation.

Nothing here touches a renderer or a device, on purpose: the property worth testing is a whole number of stops, and a test that needed a GPU could not assert it.

Properties

NameTypeDescription
nowreadonlyoptional() => numberThe clock, in milliseconds.
More

Injected so a test can move time by hand. Every property this class has is a whole number of milliseconds and a whole number of stops; measuring them against a real clock would be measuring the machine the suite ran on.

forgetreadonlyoptionalnumberHow fast the worst-stop estimate forgets, as a factor applied once per call.
More

One per cent by default, and the number is load-bearing. Five per cent was tried by a consumer and is wrong: the estimate falls below the real cost inside a single crossing of a town, the guard lets a second stop start with no room for it, and a call costs the budget plus a stop rather than the larger of the two — which is the whole thing the guard exists to prevent.