Moving layers redraw as fast as they move on screen, 3 to 30 times a second

Satellites, flights and vessels held the render loop at the display's rate
while they were on, so a view of slow-moving marks drew 100-170 frames a
second. Each now reads how fast its fastest mark crosses the screen and asks
for a frame whenever that mark would move half a pixel: never fewer than 3 a
second (animated marks never stall), never more than 30 (room in the frame
for the rest of the scene). Below 12 a second the layer asks for one frame at
a time on a timer; from there it holds the loop at 15, 20 or 30, rates the
display divides evenly (renderPace.js).

The render governor takes a rate per hold: the highest asked wins, a hold
with no rate draws at the display's rate. Following a target is capped at
30. Steering the camera (a drag, a pinch, the wheel) still draws at the
display's rate; it ends when the last pointer lifts, the wheel rests, or the
page loses focus or is hidden.

Draw sets whose motion clock is the owner's ('frames: owner') ask for no
frames for moving rows or for rows written in place; the owner's pace does.
The vessels layer places its contacts at most 30 times a second and writes
every move of a pass to its icons in one batch.

Measured in Chrome on a still camera (draws a second, before -> after):
satellites over the whole globe 162 -> 6, at 1,500 km 114 -> 30; flights over
the whole globe 132 -> 10, Europe 53 -> 5, London 114 -> 9. Planes move at
most 0.6 px between draws.
This commit is contained in:
Sameh Khamis committed 2026-11-23 18:56:44 -08:00
1 parent 43bd25382d
commit d50f04efeb
30 files changed
+1262 -82

No files matched your search

+124
View File
@@ -9,6 +9,7 @@ import {
_resetRenderGovernorForTest,
uninstallRenderGovernor,
IDLE_FRAME_RATE,
FOLLOW_FRAME_RATE,
} from './renderGovernor.js';
import { framePortFor } from './testSupport/fakeFramePort.mjs';
@@ -293,3 +294,126 @@ test('installing again drops a camera hold the old listeners can no longer relea
assert.equal(scene.requestRenderMode, true);
assert.equal(timers.pending, 0);
});
test('a hold may cap the rate: the highest asked wins, an uncapped hold is the display rate', () => {
const { viewer, scene } = makeViewer();
const frame = framePortFor(viewer.scene);
installRenderGovernor(frame);
holdContinuousRender('satellites', { maxFps: 15 });
assert.equal(scene.targetFps, 15);
holdContinuousRender('flights', { maxFps: 30 });
assert.equal(scene.targetFps, 30, 'the highest asked');
holdContinuousRender('flights', { maxFps: 20 });
assert.equal(scene.targetFps, 20, 'a holder lowering its rate');
holdContinuousRender('traffic');
assert.equal(scene.targetFps, 0, 'a hold without a rate: the display rate');
releaseContinuousRender('traffic');
assert.equal(scene.targetFps, 20);
releaseContinuousRender('flights');
assert.equal(scene.targetFps, 15);
releaseContinuousRender('satellites');
assert.equal(scene.targetFps, IDLE_FRAME_RATE);
});
test('the renderer holding the loop itself asks for no rate: the display rate', () => {
const { viewer, scene } = makeViewer();
const frame = framePortFor(viewer.scene);
installRenderGovernor(frame);
const release = frame.holdContinuous('effects:animated');
holdContinuousRender('satellites', { maxFps: 15 });
assert.equal(scene.targetFps, 0);
release();
assert.equal(scene.targetFps, 15, 'heard as soon as the renderer lets go');
const again = frame.holdContinuous('effects:animated');
assert.equal(scene.targetFps, 0, 'and as soon as it holds again');
again();
releaseContinuousRender('satellites');
assert.equal(scene.targetFps, IDLE_FRAME_RATE);
});
test('a camera carried by a followed target draws at the follow rate unless a pointer steers it', () => {
const previousWindow = globalThis.window;
const page = new EventTarget();
globalThis.window = page;
try {
const { viewer, scene } = makeViewer();
const camera = makeCamera();
installRenderGovernor(framePortFor(viewer.scene), { camera });
camera.raise('moveStart');
assert.equal(scene.targetFps, 0, 'a camera move: the display rate');
holdContinuousRender('tracked-entity', { maxFps: FOLLOW_FRAME_RATE });
assert.equal(scene.targetFps, FOLLOW_FRAME_RATE, 'following');
assert.equal(FOLLOW_FRAME_RATE, 30);
page.dispatchEvent(new Event('pointerdown'));
assert.equal(scene.targetFps, 0, 'steering: the display rate');
page.dispatchEvent(new Event('pointerup'));
assert.equal(scene.targetFps, FOLLOW_FRAME_RATE);
releaseContinuousRender('tracked-entity');
assert.equal(scene.targetFps, 0, 'the camera moving on its own');
camera.raise('moveEnd');
assert.equal(scene.targetFps, IDLE_FRAME_RATE);
} finally {
_resetRenderGovernorForTest();
if (previousWindow === undefined) delete globalThis.window;
else globalThis.window = previousWindow;
}
});
test('steering ends when the page loses focus, and a wheel moment ending never ends a drag', () => {
const previousWindow = globalThis.window;
const page = new EventTarget();
globalThis.window = page;
try {
const timers = fakeTimers();
const { viewer, scene } = makeViewer();
installRenderGovernor(framePortFor(viewer.scene), timers);
holdContinuousRender('tracked-entity', { maxFps: FOLLOW_FRAME_RATE });
holdContinuousRender('camera');
page.dispatchEvent(new Event('pointerdown'));
assert.equal(scene.targetFps, 0, 'dragging: the display rate');
// Let go over another window: the page never hears the release.
page.dispatchEvent(new Event('blur'));
assert.equal(scene.targetFps, FOLLOW_FRAME_RATE, 'focus lost: steering ends');
// A wheel turn, then a drag begun before its moment ends.
page.dispatchEvent(new Event('wheel'));
page.dispatchEvent(new Event('pointerdown'));
timers.run();
assert.equal(scene.targetFps, 0, 'the drag goes on at the display rate');
page.dispatchEvent(new Event('pointerup'));
assert.equal(scene.targetFps, FOLLOW_FRAME_RATE);
} finally {
_resetRenderGovernorForTest();
if (previousWindow === undefined) delete globalThis.window;
else globalThis.window = previousWindow;
}
});
test('a pinch steers until its last finger lifts; an element losing focus is not the page losing it', () => {
const previousWindow = globalThis.window;
const page = new EventTarget();
globalThis.window = page;
try {
const { viewer, scene } = makeViewer();
installRenderGovernor(framePortFor(viewer.scene), fakeTimers());
holdContinuousRender('tracked-entity', { maxFps: FOLLOW_FRAME_RATE });
holdContinuousRender('camera');
const pointer = (type, pointerId) => Object.assign(new Event(type), { pointerId });
page.dispatchEvent(pointer('pointerdown', 1));
page.dispatchEvent(pointer('pointerdown', 2));
page.dispatchEvent(pointer('pointerup', 1));
assert.equal(scene.targetFps, 0, 'one finger still down');
// The search box's blur reaches the window's capturing listener.
const field = new EventTarget();
field.addEventListener('blur', () => {});
const blur = new Event('blur');
Object.defineProperty(blur, 'target', { value: field });
page.dispatchEvent(blur);
assert.equal(scene.targetFps, 0, 'still steering');
page.dispatchEvent(pointer('pointerup', 2));
assert.equal(scene.targetFps, FOLLOW_FRAME_RATE);
} finally {
_resetRenderGovernorForTest();
if (previousWindow === undefined) delete globalThis.window;
else globalThis.window = previousWindow;
}
});