Compare commits

..
Author SHA1 Message Date
Mazeyar Moeini FeizabadiandClaude Fable 5.2 ad369eb0de docs(changelog): add the #1713 fragment
Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-13 16:06:06 +01:00
Mazeyar Moeini FeizabadiandClaude Fable 5.2 0b5ae6386e perf(weather): apply the infrared cloud transfer from a lookup table, in place
The Satellite clouds transfer ran a power curve per pixel and wrote the
result back from a full-size copy. On the 4096x2048 images the 3D Tiles
host draws, that held the page for about 150 ms per image. The scale
depends only on the brightest channel, so it is now worked out once per
byte value and applied to the canvas pixels in place. Output bytes are
unchanged.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-13 14:42:57 +01:00
13 changed files with 112 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).
+3
View File
@@ -0,0 +1,3 @@
- Halve the time the satellite cloud image takes to prepare on the 3D Tiles
map by applying its transparency curve from a lookup table, in place
(mazy1998, #1713).
-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);
}
});
-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;
+34 -13
View File
@@ -1,22 +1,29 @@
export const INFRARED_ALPHA_T0 = 0.4;
export const INFRARED_ALPHA_T1 = 0.7;
/** Return display pixels without changing RGB or the source RGBA bytes.
function infraredAmount(strength) {
return strength === 'full'
? 0
: strength === 'filtered' || !Number.isFinite(strength)
? 1
: Math.max(0, Math.min(100, strength)) / 100;
}
/** Scale each pixel's alpha in place; RGB is left as it is. The scale depends
* only on the brightest channel, so it is worked out once for each of the 256
* byte values instead of once per pixel: a 4096×2048 image has 8.4 million
* pixels and the power curve per pixel held the page for over 100 ms. The
* table holds the same numbers the per-pixel formula produced, so the output
* bytes are unchanged.
* `strength` is 0–100: zero is the full image and 100 is the cloud key.
*/
export function infraredAlpha(rgba, strength = 'filtered') {
const pixels = new Uint8ClampedArray(rgba);
const amount =
strength === 'full'
? 0
: strength === 'filtered' || !Number.isFinite(strength)
? 1
: Math.max(0, Math.min(100, strength)) / 100;
export function applyInfraredAlpha(pixels, strength = 'filtered') {
const amount = infraredAmount(strength);
if (amount === 0) return pixels;
for (let i = 0; i < pixels.length; i += 4) {
const scale = new Float64Array(256);
for (let value = 0; value < 256; value++) {
// Match Cesium's czm_srgbToLinear conversion in draped imagery.
const linearMax =
(Math.max(rgba[i], rgba[i + 1], rgba[i + 2]) / 255) ** 2.2;
const linearMax = (value / 255) ** 2.2;
const t = Math.max(
0,
Math.min(
@@ -26,7 +33,21 @@ export function infraredAlpha(rgba, strength = 'filtered') {
),
);
const filtered = t * t * (3 - 2 * t);
pixels[i + 3] = rgba[i + 3] * (1 - amount + filtered * amount);
scale[value] = 1 - amount + filtered * amount;
}
for (let i = 0; i < pixels.length; i += 4) {
const r = pixels[i];
const g = pixels[i + 1];
const b = pixels[i + 2];
const max = r > g ? (r > b ? r : b) : g > b ? g : b;
pixels[i + 3] = pixels[i + 3] * scale[max];
}
return pixels;
}
/** Return display pixels without changing RGB or the source RGBA bytes.
* `strength` is 0–100: zero is the full image and 100 is the cloud key.
*/
export function infraredAlpha(rgba, strength = 'filtered') {
return applyInfraredAlpha(new Uint8ClampedArray(rgba), strength);
}
+41
View File
@@ -1,6 +1,7 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {
applyInfraredAlpha,
infraredAlpha,
INFRARED_ALPHA_T0,
INFRARED_ALPHA_T1,
@@ -61,3 +62,43 @@ test('full infrared preserves every channel including partial and zero alpha', (
]);
assert.deepEqual(infraredAlpha(pixels, 'full'), pixels);
});
test('the lookup table gives the per-pixel curve byte for byte, in place', () => {
// The transfer as it was written per pixel, before the table.
const perPixel = (rgba, amount) => {
const out = new Uint8ClampedArray(rgba);
for (let i = 0; i < out.length; i += 4) {
const linearMax =
(Math.max(rgba[i], rgba[i + 1], rgba[i + 2]) / 255) ** 2.2;
const t = Math.max(
0,
Math.min(
1,
(linearMax - INFRARED_ALPHA_T0) /
(INFRARED_ALPHA_T1 - INFRARED_ALPHA_T0),
),
);
out[i + 3] = rgba[i + 3] * (1 - amount + t * t * (3 - 2 * t) * amount);
}
return out;
};
// Every brightest-channel value in each channel, against a spread of alphas.
const bytes = [];
for (let value = 0; value < 256; value++)
for (const alpha of [0, 1, 37, 128, 200, 254, 255]) {
bytes.push(value, 0, 0, alpha);
bytes.push(value >> 1, value, 0, alpha);
bytes.push(0, value >> 2, value, alpha);
}
const source = new Uint8ClampedArray(bytes);
for (const strength of [1, 33, 50, 99, 100, 'filtered', Number.NaN]) {
const amount = Number.isFinite(strength) ? strength / 100 : 1;
const pixels = source.slice();
assert.equal(applyInfraredAlpha(pixels, strength), pixels);
assert.deepEqual(pixels, perPixel(source, amount), `strength ${strength}`);
}
for (const strength of [0, 'full']) {
const pixels = source.slice();
assert.deepEqual(applyInfraredAlpha(pixels, strength), source);
}
});
+3 -2
View File
@@ -6,7 +6,7 @@ import {
drawWeatherPixels,
closeWeatherPixels,
} from './source.js';
import { infraredAlpha } from './infraredAlpha.js';
import { applyInfraredAlpha } from './infraredAlpha.js';
export const MAX_MOSAIC_BYTES = 4 * 1024 * 1024;
@@ -31,7 +31,8 @@ export function processInfraredImage(
function applyInfraredTransfer(context, canvas, mode) {
const pixels = context.getImageData(0, 0, canvas.width, canvas.height);
pixels.data.set(infraredAlpha(pixels.data, mode));
// In place: a copy of a 4096×2048 image is 33 MB, made and written back.
applyInfraredAlpha(pixels.data, mode);
context.putImageData(pixels, 0, 0);
}
+22
View File
@@ -26,6 +26,28 @@ function canvas() {
return output;
}
test('the transfer is applied to the canvas pixels in place, with no copy written back', () => {
let read = null;
const output = {};
output.getContext = () => ({
drawImage() {},
getImageData: () => {
read = { data: new Uint8ClampedArray([194, 0, 0, 200]) };
// A second full-size buffer copied over the first is what this guards.
read.data.set = () => {
throw new Error('the canvas pixels were overwritten from a copy');
};
return read;
},
putImageData: (pixels) => {
output.pixels = pixels;
},
});
processInfraredImage({ width: 1, height: 1 }, 'filtered', () => output);
assert.equal(output.pixels, read);
assert.deepEqual([...read.data], [194, 0, 0, 98]);
});
test('decoded pixels are processed once on a same-sized canvas', () => {
const image = { width: 1, height: 1 };
const output = processInfraredImage(image, 'filtered', canvas);