vessels: move drawn vessels following the clock once they would move half a pixel

A profile of about 9,000 vessels following a playing world clock spent
~13 ms of every frame in the clock pass, moving every drawn vessel a
fraction of a pixel, and ~4 ms more re-uploading their billboards.

- Drawn vessels move again once the fastest would have moved half a pixel
  on screen at the speed each last moved (measured from the world time it
  was drawn at), at least once a second, and at once when the camera moves
  or changes height by a tenth of its height or the view zooms. A pass that
  holds them back asks for a frame, so a paused clock settles on the time.
- Hidden vessels move a share of them each pass, each within 250 ms, rather
  than all of them in one frame; the visibility pass moves one coming into
  view to the time first.
- A vessel's three positions are written from one surface point and normal
  (Cesium's own formula) instead of three fromDegrees calls; the unused
  normal is dropped. The great-circle step builds no arrays.

The pass falls from 4.6 ms to 0.37 ms a frame on average in a benchmark of
9,000 vessels (3,000 drawn) at 240 frames a second.
This commit is contained in:
Sameh Khamis committed 2026-11-15 13:35:11 -08:00
1 parent 8af8c086a6
commit 1f6e8914f2
5 files changed
+589 -114

No files matched your search

+21 -22
View File
@@ -55,37 +55,36 @@ export function vesselPositionAt(record, tMs) {
const RAD = Math.PI / 180;
/** The point `fraction` of the way from one position to another. */
/** The point `fraction` of the way from one position to another. It runs
* for every drawn vessel as the clock plays, so it builds no arrays. */
function greatCircleAt(lat1, lon1, lat2, lon2, fraction) {
const p1 = unit(lat1, lon1);
const p2 = unit(lat2, lon2);
const dot = Math.min(
1,
Math.max(-1, p1[0] * p2[0] + p1[1] * p2[1] + p1[2] * p2[2]),
);
const phi1 = lat1 * RAD;
const lambda1 = lon1 * RAD;
const phi2 = lat2 * RAD;
const lambda2 = lon2 * RAD;
const cos1 = Math.cos(phi1);
const cos2 = Math.cos(phi2);
const x1 = cos1 * Math.cos(lambda1);
const y1 = cos1 * Math.sin(lambda1);
const z1 = Math.sin(phi1);
const x2 = cos2 * Math.cos(lambda2);
const y2 = cos2 * Math.sin(lambda2);
const z2 = Math.sin(phi2);
const dot = Math.min(1, Math.max(-1, x1 * x2 + y1 * y2 + z1 * z2));
const angle = Math.acos(dot);
if (angle < 1e-12) return { lat: lat2, lon: lon2 };
const a = Math.sin((1 - fraction) * angle) / Math.sin(angle);
const b = Math.sin(fraction * angle) / Math.sin(angle);
const x = a * p1[0] + b * p2[0];
const y = a * p1[1] + b * p2[1];
const z = a * p1[2] + b * p2[2];
const sinAngle = Math.sin(angle);
const a = Math.sin((1 - fraction) * angle) / sinAngle;
const b = Math.sin(fraction * angle) / sinAngle;
const x = a * x1 + b * x2;
const y = a * y1 + b * y2;
const z = a * z1 + b * z2;
return {
lat: Math.atan2(z, Math.hypot(x, y)) / RAD,
lon: Math.atan2(y, x) / RAD,
};
}
function unit(lat, lon) {
const phi = lat * RAD;
const lambda = lon * RAD;
return [
Math.cos(phi) * Math.cos(lambda),
Math.cos(phi) * Math.sin(lambda),
Math.sin(phi),
];
}
// Whether each fixes array moves, read once per array: records keep theirs
// until a snapshot brings new ones.
const moving = new WeakMap();