Compare commits

..
Author SHA1 Message Date
Mazeyar Moeini FeizabadiandClaude Fable 5.2 d37e8cf17d docs(changelog): add the #1710 fragment
Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-13 16:06:01 +01:00
Mazeyar Moeini FeizabadiandClaude Fable 5.2 3e1070a2cb perf(cctv): hold continuous rendering for video only
A still-image camera kept the scene rendering 60 times a second for as long
as it was active, though its picture changes about every ten seconds. The
projection loop now holds the continuous loop only for a video feed; a still
asks for frames for half a second after a new image is swapped onto the
plane, and a focus fade asks for one when it restyles an icon.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-13 16:03:18 +01:00
14 changed files with 268 additions and 138 deletions

No files matched your search

@@ -1,3 +0,0 @@
- Shorten the freeze when Submarine cables is switched on from about 1.4 s to
about 0.2 s. Landing markers are now shown a few dozen per frame instead of
all at once (mazy1998, #1707).
@@ -0,0 +1,3 @@
- A still-image CCTV camera no longer keeps the scene rendering 60 times a
second. Only a video feed holds continuous rendering; a still redraws when a
new image arrives (mazy1998, #1710).
-6
View File
@@ -8158,12 +8158,6 @@ Cesium's multipart suffixes. Each segment gets its own feature's styling, click
destination and horizon-culling reference, and each source feature has one
reference stem. The source collections are not modified.
Landing markers are ground-clamped billboards, and Cesium reads the terrain
height as it creates each one. They start hidden and the horizon sweep shows
the visible ones 48 per rendered frame (`CABLE_LANDING_REVEALS_PER_FRAME`),
so switching the layer on does not do every read in one task; hiding is still
immediate.
Natural Earth regions and neighborhood polygon lookup are package exports.
Their existing lazy loaders, retry behavior, bundled datasets and attribution
are unchanged. The cable dataset remains CC BY-NC-SA 3.0 and is not covered by
@@ -3,7 +3,6 @@ import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import * as Cesium from 'cesium';
import { MAP_STACKS } from '../mapStackController.js';
import { CABLE_LANDING_REVEALS_PER_FRAME } from '../layers/submarineCables/policy.js';
import {
CABLE_LABEL_DEPTH_DECISION,
CABLE_OVERLAY_COLLISION_CAPACITY,
@@ -2004,62 +2003,3 @@ test('every bundled cable segment is associated with its source feature', async
env.layer.destroy(env.viewer);
}
});
test('landing markers are revealed a few per frame, never all in one', async () => {
// Node has no canvas for GeoJSON point pins, so short lines stand in for
// the markers (see createRealCableLayerHarness); the staging is the same.
const count = CABLE_LANDING_REVEALS_PER_FRAME * 2 + 10;
const landingPoints = Array.from({ length: count }, (_, i) => {
const lon = -45 + (i % 20) * 0.5;
const lat = 30 + Math.floor(i / 20);
return {
type: 'Feature',
id: `landing-${i}`,
properties: { id: `landing-${i}`, name: `Landing ${i}` },
geometry: {
type: 'LineString',
coordinates: [
[lon, lat],
[lon + 0.01, lat + 0.01],
],
},
};
});
const env = await createRealCableLayerHarness({
source: geometrySource([], landingPoints),
});
try {
let renderRequests = 0;
env.viewer.scene.requestRender = () => {
renderRequests++;
};
const entities = env.dataSources[1].entities.values;
const shown = () => entities.filter((entity) => entity.show).length;
assert.equal(entities.length, count);
assert.equal(shown(), 0, 'nothing is shown before the first sweep');
env.raiseSweep();
assert.equal(shown(), CABLE_LANDING_REVEALS_PER_FRAME);
assert.ok(renderRequests > 0, 'another frame is asked for');
env.raiseSweep();
assert.equal(shown(), CABLE_LANDING_REVEALS_PER_FRAME * 2);
env.raiseSweep();
assert.equal(shown(), count, 'every visible marker ends up shown');
renderRequests = 0;
env.raiseSweep();
assert.equal(renderRequests, 0, 'a finished reveal asks for no frames');
// Markers over the horizon are hidden at once and are not revealed.
env.viewer.camera.positionWC = Cesium.Cartesian3.fromDegrees(
140,
-35,
4_500_000,
);
for (const fn of env.listeners.moveEnd) fn();
env.raiseSweep();
assert.equal(shown(), 0);
} finally {
env.layer.destroy(env.viewer);
}
});
+7 -5
View File
@@ -144,33 +144,35 @@ export function createFrames({ state: layerState, services, parts, source }) {
* the double-buffer canvas reference, throttled to PROJECTION_TEXTURE_SWAP_MS.
*
* @param {Object} record - Camera record with an initialized projection runtime.
* @returns {boolean} Whether a new image was put on the plane.
*/
function refreshProjectionTextures(record) {
const runtime = record?.projection;
if (!runtime || runtime.mode === 'video') return;
if (!runtime || runtime.mode === 'video') return false;
const now = Date.now();
if (
now - parts.model.safeNumber(runtime.lastTextureSwapAt, 0) <
PROJECTION_TEXTURE_SWAP_MS
)
return;
return false;
const planeShowing = !!(runtime.planeEntity?.show && runtime.planeMaterial);
if (!planeShowing) return;
if (!planeShowing) return false;
// Only swap when the canvas content actually changed since the last swap.
// Frames land every ~10 s but this runs at 1 Hz — swapping an UNCHANGED
// canvas re-uploads the texture for nothing, and each material image
// reassignment is a flash opportunity on the live plane (owner field test
// 2026-07-04: intermittent white flashes on the monitor plane).
if (runtime.canvasStamp === runtime.lastSwappedCanvasStamp) return;
if (runtime.canvasStamp === runtime.lastSwappedCanvasStamp) return false;
const buffer = paintNextProjectionBuffer(runtime);
if (!buffer) return;
if (!buffer) return false;
runtime.lastTextureSwapAt = now;
runtime.lastSwappedCanvasStamp = runtime.canvasStamp;
runtime.planeMaterial.image = buffer;
return true;
}
/**
+5
View File
@@ -123,6 +123,11 @@ export const CCTV_CALIBRATION_STORAGE_KEY_V2 =
export const PROJECTION_TEXTURE_SWAP_MS = 1000;
// A still-image projection changes only when a new still is swapped onto the
// plane, so the scene renders for this long after a swap (Cesium binds the new
// image over the next frames) and is otherwise left idle.
export const PROJECTION_SWAP_RENDER_MS = 500;
// V2 frustum geometry (design §2a/§6): the far-cap center + corners never sink
// below groundAlt + this clearance, so a fabricated pitch (-24°) cannot bury
// the monitor plane in the 3D tiles. Exported for the unit suite.
+29 -8
View File
@@ -6,6 +6,7 @@ import {
PLANE_OUTLINE_COLOR,
PROJECTION_CANVAS_WIDTH,
PROJECTION_CANVAS_HEIGHT,
PROJECTION_SWAP_RENDER_MS,
} from './policy.js';
export function createProjection({
@@ -14,7 +15,15 @@ export function createProjection({
parts,
source,
}) {
const { holdContinuousRender, releaseContinuousRender } = services.render;
const {
holdContinuousRender,
releaseContinuousRender,
governorRequestRender = () => {},
} = services.render;
// Until this time (performance.now) the projection loop asks for a frame on
// every tick: after a still is swapped onto the plane, and after an edge
// that re-arms the loop (activation, projection shown).
let renderUntil = 0;
/**
* Build the protected label associated with one active monitor plane.
@@ -352,12 +361,9 @@ export function createProjection({
}
function startProjectionLoop() {
renderUntil = performance.now() + PROJECTION_SWAP_RENDER_MS;
if (layerState._projectionRaf) return;
if (!parts.model.projectionLoopIsNeeded()) return;
// The armed projection loop uploads video textures / runs focus fades per
// frame — the scene must render continuously while it runs. Released when
// the tick self-stops. (perf wave 2)
holdContinuousRender('cctv-projection');
const tick = () => {
if (!layerState._viewer || !parts.model.projectionLoopIsNeeded()) {
@@ -366,15 +372,30 @@ export function createProjection({
return;
}
parts.rendering.refreshCctvFocusStyles(performance.now());
const now = performance.now();
const restyled = parts.rendering.refreshCctvFocusStyles(now);
const active = parts.selection.getActiveRecord();
let video = false;
if (layerState._enabled && layerState._showProjection && active) {
ensureProjectionRuntime(active);
if (active.projection && !active.projection.video) {
parts.frames.drawProjectionFrame(active);
parts.frames.refreshProjectionTextures(active);
}
if (parts.frames.refreshProjectionTextures(active))
renderUntil = now + PROJECTION_SWAP_RENDER_MS;
} else video = Boolean(active.projection?.video);
}
// Only a video feed changes the scene on every frame, so only video
// holds the continuous loop. A still lands about every ten seconds and
// a focus fade restyles icons every 80 ms; each asks for the frames it
// needs. Holding for stills rendered the scene 60 times a second for as
// long as a camera was active. (perf wave 2 held for both.)
if (video) holdContinuousRender('cctv-projection');
else {
releaseContinuousRender('cctv-projection');
if (restyled || now < renderUntil)
governorRequestRender('cctv-projection');
}
layerState._projectionRaf = requestAnimationFrame(tick);
+211
View File
@@ -0,0 +1,211 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { createProjection } from './projection.js';
import { createFrames } from './frames.js';
import {
PROJECTION_SWAP_RENDER_MS,
PROJECTION_TEXTURE_SWAP_MS,
} from './policy.js';
/** The projection loop on a hand-cranked clock, with the render governor's calls recorded. */
function harness(t, { video = false, showProjection = true } = {}) {
let clock = 1000;
const frames = [];
const original = {
now: performance.now,
request: globalThis.requestAnimationFrame,
cancel: globalThis.cancelAnimationFrame,
};
performance.now = () => clock;
globalThis.requestAnimationFrame = (step) => frames.push(step);
globalThis.cancelAnimationFrame = () => frames.splice(0);
t.after(() => {
performance.now = original.now;
globalThis.requestAnimationFrame = original.request;
globalThis.cancelAnimationFrame = original.cancel;
});
const holds = new Set();
const calls = { hold: 0, requests: 0, draws: 0 };
const record = {
camera: { id: 'cam-1' },
projection: { video: video ? {} : null, mode: video ? 'video' : 'image' },
};
const scene = { needed: true, swap: false, restyled: false };
const state = {
_viewer: {},
_enabled: true,
_showProjection: showProjection,
_projectionRaf: 0,
_projectionEntities: [],
};
const projection = createProjection({
state,
services: {
render: {
holdContinuousRender(owner) {
calls.hold++;
holds.add(owner);
},
releaseContinuousRender: (owner) => holds.delete(owner),
governorRequestRender: () => calls.requests++,
},
},
parts: {
model: { projectionLoopIsNeeded: () => scene.needed },
rendering: { refreshCctvFocusStyles: () => scene.restyled },
selection: { getActiveRecord: () => record },
frames: {
drawProjectionFrame: () => calls.draws++,
refreshProjectionTextures() {
const swapped = scene.swap;
scene.swap = false;
return swapped;
},
},
},
source: {},
});
return {
projection,
state,
record,
scene,
holds,
calls,
/** Run `count` animation frames 16 ms apart; returns the frames requested in them. */
run(count = 1) {
const before = calls.requests;
for (let i = 0; i < count; i++) {
clock += 16;
frames.shift()?.();
}
return calls.requests - before;
},
advance(ms) {
clock += ms;
},
get queued() {
return frames.length;
},
};
}
test('a still-image camera never holds the continuous render loop', (t) => {
const h = harness(t);
h.projection.startProjectionLoop();
h.run(600);
assert.equal(h.calls.hold, 0);
assert.equal(h.holds.size, 0);
assert.equal(h.calls.draws, 600, 'the loop still polls for a new still');
assert.equal(h.queued, 1, 'and stays armed');
});
test('a new still on the plane is rendered, then the scene goes idle again', (t) => {
const h = harness(t);
h.projection.startProjectionLoop();
// Arming the loop (activation, projection shown) renders its first frames.
assert.ok(h.run(5) === 5);
h.advance(PROJECTION_SWAP_RENDER_MS);
assert.equal(h.run(120), 0, 'an unchanged still asks for no frame');
h.scene.swap = true;
assert.equal(h.run(1), 1, 'the tick that swaps the image asks for a frame');
const settling = Math.floor(PROJECTION_SWAP_RENDER_MS / 16) - 2;
assert.equal(h.run(settling), settling, 'and so do the ticks while it binds');
h.advance(PROJECTION_SWAP_RENDER_MS);
assert.equal(h.run(120), 0);
assert.equal(h.holds.size, 0);
});
test('activating another camera while the loop runs renders its first frames', (t) => {
const h = harness(t);
h.projection.startProjectionLoop();
h.advance(PROJECTION_SWAP_RENDER_MS * 2);
assert.equal(h.run(10), 0);
h.projection.startProjectionLoop();
assert.equal(h.run(10), 10);
assert.equal(h.queued, 1, 'still one loop');
});
test('a video camera holds continuous render until it stops being video', (t) => {
const h = harness(t, { video: true });
h.projection.startProjectionLoop();
h.run(3);
assert.deepEqual([...h.holds], ['cctv-projection']);
assert.equal(h.calls.draws, 0, 'Cesium updates the video texture itself');
// The stream failed over to stills.
h.record.projection.video = null;
h.run(1);
assert.equal(h.holds.size, 0);
h.record.projection.video = {};
h.run(1);
assert.deepEqual([...h.holds], ['cctv-projection']);
h.projection.stopProjectionLoop();
assert.equal(h.holds.size, 0);
});
test('a focus fade asks for a frame only on the ticks that restyle an icon', (t) => {
const h = harness(t, { showProjection: false });
h.projection.startProjectionLoop();
h.advance(PROJECTION_SWAP_RENDER_MS * 2);
assert.equal(h.run(10), 0);
h.scene.restyled = true;
assert.equal(h.run(4), 4);
h.scene.restyled = false;
assert.equal(h.run(10), 0);
assert.equal(h.holds.size, 0);
});
test('the loop releases and stops when it has no work', (t) => {
const h = harness(t, { video: true });
h.projection.startProjectionLoop();
h.run(2);
h.scene.needed = false;
h.run(1);
assert.equal(h.holds.size, 0);
assert.equal(h.state._projectionRaf, 0);
assert.equal(h.queued, 0);
});
test('refreshProjectionTextures reports whether it put a new image on the plane', (t) => {
const previousDocument = globalThis.document;
globalThis.document = {
createElement: () => ({
getContext: () => ({ clearRect() {}, drawImage() {} }),
}),
};
t.after(() => {
if (previousDocument === undefined) delete globalThis.document;
else globalThis.document = previousDocument;
});
const frames = createFrames({
state: {},
services: {},
parts: { model: { safeNumber: (value, fallback) => value ?? fallback } },
source: {},
});
const runtime = {
mode: 'image',
canvas: {},
canvasStamp: 1,
planeEntity: { show: true },
planeMaterial: { image: null },
};
const record = { projection: runtime };
assert.equal(frames.refreshProjectionTextures(record), true);
const first = runtime.planeMaterial.image;
assert.ok(first);
// Unchanged canvas: nothing to render.
runtime.lastTextureSwapAt -= PROJECTION_TEXTURE_SWAP_MS;
assert.equal(frames.refreshProjectionTextures(record), false);
assert.equal(runtime.planeMaterial.image, first);
runtime.canvasStamp = 2;
assert.equal(frames.refreshProjectionTextures(record), true);
assert.notEqual(runtime.planeMaterial.image, first);
runtime.planeEntity.show = false;
runtime.canvasStamp = 3;
runtime.lastTextureSwapAt -= PROJECTION_TEXTURE_SWAP_MS;
assert.equal(frames.refreshProjectionTextures(record), false);
assert.equal(frames.refreshProjectionTextures({ projection: { mode: 'video' } }), false);
});
+4 -2
View File
@@ -61,8 +61,8 @@ export function createRendering({
!layerState._viewer ||
!focusPassIsNeeded(target, layerState._activeFocusStyleCount)
)
return;
if (nowMs - layerState._lastFocusStyleAt < 80) return;
return false;
if (nowMs - layerState._lastFocusStyleAt < 80) return false;
layerState._lastFocusStyleAt = nowMs;
const scene = layerState._viewer.scene;
const camera = layerState._viewer.camera;
@@ -82,6 +82,8 @@ export function createRendering({
baseColorFor: cameraColorFor,
});
layerState._activeFocusStyleCount = result.activeCount;
// Whether an icon was restyled, so the caller can ask for a frame.
return result.writes > 0;
}
/**
-5
View File
@@ -185,10 +185,6 @@ export function createIngestion({ state, parts, source }) {
if (!reference) return;
parts.rendering.styleLandingEntity(entity, feature);
// Hidden until the sweep reveals it: a shown landing marker reads the
// terrain height as Cesium creates it, and all of them at once froze
// the page (see CABLE_LANDING_REVEALS_PER_FRAME).
entity.show = false;
parts.interaction.registerPickEntity(entity, {
kind: 'landing-point',
reference,
@@ -197,7 +193,6 @@ export function createIngestion({ state, parts, source }) {
state._surfaceRecords.push({
entity,
base: Cesium.Cartesian3.fromDegrees(reference.lon, reference.lat, 0),
staged: true,
});
if (landingReferences.has(index)) return;
landingReferences.add(index);
+6 -4
View File
@@ -38,10 +38,12 @@ export function createLifecycle({ state, parts, source, mapStackEventTarget }) {
// never emit moveEnd — reach the motion fallback. No render is
// requested for a fallback sweep: it only fires while the camera is
// already moving, so frames are flowing by construction.
if (!state._enabled || !state._loaded) return;
// Landing markers left over from the last sweep, a few per frame.
parts.rendering.revealLandingMarkers();
if (!state._referenceSweepGate.shouldRun(viewer.camera)) return;
if (
!state._enabled ||
!state._loaded ||
!state._referenceSweepGate.shouldRun(viewer.camera)
)
return;
parts.rendering.updateReferenceVisibility();
},
);
-10
View File
@@ -66,16 +66,6 @@ export const CABLE_LABEL_DEPTH_DECISION = Object.freeze({
depthTested: false,
});
/**
* Landing markers shown per rendered frame. Each one is a ground-clamped
* billboard, and Cesium reads the terrain height when it creates one.
* Showing all 1,917 in the frame after the layer was switched on did those
* reads in a single task (measured 1.2 s on a loaded globe); a few dozen per
* frame keeps each frame short and the markers still fill in within a second.
*/
export const CABLE_LANDING_REVEALS_PER_FRAME = 48;
/**
* `MAP_STACKS` ids that render imagery on the SHOWN Cesium globe (the ion
* Bing stacks + OSM). Deliberately an explicit allowlist, not "anything that
+3 -30
View File
@@ -3,7 +3,6 @@ import {
probeTranslucentMarkerBlend,
commitTranslucentMarkerBlend,
} from './surface.js';
import { CABLE_LANDING_REVEALS_PER_FRAME } from './policy.js';
import {
clampLabel,
createCableOverlayEntry,
@@ -41,7 +40,6 @@ export function createRendering({ state }) {
state._referenceDataSource = null;
state._referenceRecords = [];
state._surfaceRecords = [];
state._pendingLandingReveals.length = 0;
state._pickByEntity = new WeakMap();
state._referenceLabelCount = 0;
state._publishScratch.length = 0;
@@ -203,26 +201,6 @@ export function createRendering({ state }) {
state._referenceRecords.push(record);
}
/**
* Show the next few landing markers the last sweep found visible, and ask
* for another frame while any are left. Called from the sweep and then once
* per rendered frame, so a parked camera costs nothing once the list is
* empty.
*/
function revealLandingMarkers() {
const pending = state._pendingLandingReveals;
if (!pending.length) return;
let budget = CABLE_LANDING_REVEALS_PER_FRAME;
while (pending.length && budget > 0) {
const record = pending.pop();
if (!record.visible || record.entity.show) continue;
record.entity.show = true;
budget--;
}
if (pending.length) state._viewer?.scene?.requestRender?.();
}
function updateReferenceVisibility() {
if (!state._enabled || !state._viewer?.camera) return;
const cameraPos = state._viewer.camera.positionWC;
@@ -246,16 +224,12 @@ export function createRendering({ state }) {
if (visible)
updateCableReferenceStem(record, cameraPos, canvasHeight, fov);
}
state._pendingLandingReveals.length = 0;
for (const record of state._surfaceRecords) {
const visible = occluder.isPointVisible(record.base);
record.visible = visible;
if (record.entity.show === visible) continue;
// Landing markers are shown a few per frame; hiding is immediate.
if (visible && record.staged) state._pendingLandingReveals.push(record);
else record.entity.show = visible;
if (record.entity.show !== visible) {
record.entity.show = visible;
}
}
revealLandingMarkers();
const winners = selectCableReferenceLabelWinners(state._referenceRecords);
let changed = winners.length !== state._lastPublishedCount;
for (let i = 0; i < winners.length; i++) {
@@ -295,7 +269,6 @@ export function createRendering({ state }) {
applyCableClassification,
styleLandingEntity,
addReferenceStem,
revealLandingMarkers,
updateReferenceVisibility,
};
}
-5
View File
@@ -51,11 +51,6 @@ export function createState({ sweepClock, overlayHost }) {
state._surfaceRecords = [];
/** Landing records the last sweep found visible but not shown yet; drained
* a few per frame (CABLE_LANDING_REVEALS_PER_FRAME). */
state._pendingLandingReveals = [];
state._clickHandler = null;
state._preRenderRemover = null;