Renderer · interface
GovernorLimits
Hold a frame budget by moving the drawing-buffer scale, and nothing else.
Explained in Hello world.
interface GovernorLimitsimport type { GovernorLimits } from '@driftengine/core';In depth
This is the safety net the GPU-budget design asks for, and the reason it is worth having is that it works on hardware nobody here owns — including hardware that does not exist yet. One of the three players whose reports started that design found the cure by hand: they shrank the browser window until the game was smooth. This does the same thing without asking anyone to.
Pure by design: no GL, no DOM, no clock. Frame times come in, a new scale comes out, and the caller decides what to do with it. That is what makes it testable at all, because every device it exists for is one no test machine has.
Asymmetric on purpose. Dropping is fast, because a player at 6 fps needs relief now. Raising is slow and waits behind several consecutive good windows, because a resolution that oscillates is more visible than one that is slightly too low.
Properties
| Name | Type | Description |
|---|---|---|
budgetMsreadonly | number | The frame time a frame is allowed, in milliseconds. Longer than this is a long frame.More40 rather than 16.67, and that gap is the tolerance. This is not a governor for
squeezing a machine from 55 fps to 60: it exists for the parts that render at 4 to 9
fps, and a trigger anywhere near the vsync interval would spend its life reacting to
jitter on machines that are entirely fine. It is |
badSharereadonly | number | Share of a window's frames that must be long before the window counts as bad.MoreThis is the guard that makes a busy high-end machine safe. One hitch in sixty frames is a 1.7% share and decides nothing; a garbage collection, a shader compile, a texture upload or another application grabbing the GPU all look like that. Half the window being long is not a hitch, it is the machine. |
minScalereadonly | number | Never go below this. A soft picture beats a slideshow. |
windowFramesreadonly | number | Frames per decision. One slow frame is noise; a window of them is evidence. |
badWindowsreadonly | number | Consecutive bad windows before the scale actually moves.MoreThe second half of the tolerance, and the same reasoning |
dropStepreadonly | number | How far to drop in one decision. |
raiseStepreadonly | number | How far to raise in one decision. Deliberately smaller than dropStep. |
raisePatiencereadonly | number | Consecutive clean windows required before raising at all. |