mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Recent community wildlife observations, as a new Wildlife group in the layer panel. - Server: keyless iNaturalist proxy (v2 observations with only the projected fields; undocumented v1 UTFGrid density tiles, decoded on the server) sharing one paced queue (burst 4, ~1/s, 60/min, 8,000/day budget, up to four in flight), in-memory caches and upstream-only cooldowns; Acartia Salish Sea marine-mammal feed rounded to 0.01 degrees with comments dropped. - Layer: grid counts drawn as a soft view-ranked density glow; real sampled sightings as taxon badges at their true positions with ambient photo thumbnails and labels; obscured records stay privacy cells; a clicked sighting stays pinned through camera moves and refreshes. - Anchored photo card per selection with the single iNaturalist link; attribution in the layer row and the Data attribution popover. - Filters (CONFIRMED, taxa presets) round-trip in share links with token 9. Co-Authored-By: Claude Opus 5.5 <[email protected]>
167 lines
6.6 KiB
JavaScript
167 lines
6.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { performance, PerformanceObserver } from 'node:perf_hooks';
|
|
import test from 'node:test';
|
|
import { perfBudgetTestOptions } from '../../../scripts/run-perf-tests.mjs';
|
|
import { denseContinentalRendering } from './renderPerformanceFixtures.mjs';
|
|
import { WILDLIFE_MOVE_END_BUDGET_MS } from './performance.js';
|
|
|
|
const median = (values) =>
|
|
[...values].sort((a, b) => a - b)[Math.floor(values.length / 2)];
|
|
const percentile95 = (values) =>
|
|
[...values].sort((a, b) => a - b)[Math.floor(values.length * 0.95)];
|
|
|
|
// A GC pause is outside the layer's CPU work. Keep raw wall times in the
|
|
// diagnostic and subtract only directly observed, overlapping GC intervals
|
|
// for the strict CPU budget; never hide a slow layer phase as an outlier.
|
|
function activeMs(slice, collections) {
|
|
const start = slice.startTimeMs;
|
|
const end = start + slice.durationMs;
|
|
return (
|
|
slice.durationMs -
|
|
collections.reduce(
|
|
(sum, gc) =>
|
|
sum +
|
|
Math.max(
|
|
0,
|
|
Math.min(end, gc.startTime + gc.duration) -
|
|
Math.max(start, gc.startTime),
|
|
),
|
|
0,
|
|
)
|
|
);
|
|
}
|
|
|
|
test(
|
|
'dense continental production moveEnd pipeline yields every 4ms, including cold tiles and real Cesium billboard updates',
|
|
perfBudgetTestOptions(),
|
|
async (t) => {
|
|
// Settle CPU-triggered runtime startup before creating the cold layer;
|
|
// cells, coordinates and billboard collections remain unwarmed.
|
|
const calibrationStart = performance.now();
|
|
let calibrationChecksum = 0;
|
|
for (;;) {
|
|
const cpu = process.threadCpuUsage();
|
|
if (cpu.user + cpu.system >= 1_100_000) break;
|
|
for (let i = 0; i < 65536; i++)
|
|
calibrationChecksum =
|
|
(calibrationChecksum + i) ^ (calibrationChecksum >>> 16);
|
|
await new Promise((resolve) => setImmediate(resolve));
|
|
}
|
|
const runtimeSettleMs = performance.now() - calibrationStart;
|
|
const collections = [];
|
|
const phases = [];
|
|
const observer = new PerformanceObserver((list) => {
|
|
for (const entry of list.getEntries())
|
|
(entry.entryType === 'gc' ? collections : phases).push(entry);
|
|
});
|
|
observer.observe({ entryTypes: ['gc', 'measure'] });
|
|
const h = denseContinentalRendering();
|
|
const runs = [];
|
|
try {
|
|
for (let i = 0; i < 65; i++) {
|
|
const start = performance.now();
|
|
assert.equal(h.moveEnd((i % 4) * 3), 'pending');
|
|
const enqueueMs = performance.now() - start;
|
|
const result = h.flush();
|
|
runs.push({
|
|
startTimeMs: start,
|
|
endTimeMs: performance.now(),
|
|
enqueueMs,
|
|
...result,
|
|
});
|
|
await new Promise((resolve) => setImmediate(resolve));
|
|
}
|
|
await new Promise((resolve) => setImmediate(resolve));
|
|
for (const entry of observer.takeRecords())
|
|
(entry.entryType === 'gc' ? collections : phases).push(entry);
|
|
const warm = runs.slice(25);
|
|
const allSlices = runs.flatMap((run) => run.slices);
|
|
const warmSlices = warm.flatMap((run) => run.slices);
|
|
const activeSlices = allSlices.map((slice) =>
|
|
activeMs(slice, collections),
|
|
);
|
|
const warmTotal = warm.map((run) =>
|
|
run.slices.reduce(
|
|
(sum, slice) => sum + activeMs(slice, collections),
|
|
run.enqueueMs,
|
|
),
|
|
);
|
|
const enqueueMax = Math.max(...runs.map((run) => run.enqueueMs));
|
|
const coldMax = Math.max(
|
|
...runs[0].slices.map((slice) => activeMs(slice, collections)),
|
|
);
|
|
const sliceMax = Math.max(...activeSlices);
|
|
if (sliceMax > WILDLIFE_MOVE_END_BUDGET_MS) {
|
|
const slow = allSlices[activeSlices.indexOf(sliceMax)];
|
|
const entries = phases
|
|
.filter(
|
|
(entry) =>
|
|
entry.entryType === 'measure' &&
|
|
entry.name !== 'wildlife-sightings:moveEnd:slice' &&
|
|
entry.startTime >= slow.startTimeMs &&
|
|
entry.startTime < slow.startTimeMs + slow.durationMs,
|
|
)
|
|
.map((entry) => ({
|
|
phase: entry.name,
|
|
durationMs: entry.duration,
|
|
activeMs: activeMs(
|
|
{ startTimeMs: entry.startTime, durationMs: entry.duration },
|
|
collections,
|
|
),
|
|
}));
|
|
t.diagnostic(
|
|
`Slow slice ${JSON.stringify({ slice: slow, phases: entries, gc: collections.map((entry) => ({ start: entry.startTime, duration: entry.duration })), now: performance.now(), uptimeMs: process.uptime() * 1000 })}`,
|
|
);
|
|
}
|
|
assert.ok(
|
|
enqueueMax <= WILDLIFE_MOVE_END_BUDGET_MS,
|
|
`moveEnd enqueue ${enqueueMax.toFixed(3)}ms`,
|
|
);
|
|
assert.ok(
|
|
sliceMax <= WILDLIFE_MOVE_END_BUDGET_MS,
|
|
`longest layer CPU slice ${sliceMax.toFixed(3)}ms exceeds 4ms`,
|
|
);
|
|
assert.ok(
|
|
median(warmTotal) <= WILDLIFE_MOVE_END_BUDGET_MS,
|
|
`median full moveEnd CPU ${median(warmTotal).toFixed(3)}ms exceeds 4ms`,
|
|
);
|
|
assert.equal(warm.at(-1).cartesianBuilds, 0);
|
|
const phaseMeans = Object.fromEntries(
|
|
[
|
|
'density',
|
|
'bucket',
|
|
'rank',
|
|
'billboard-update',
|
|
'overlay-publish',
|
|
].map((name) => {
|
|
const duration = phases
|
|
.filter(
|
|
(entry) =>
|
|
entry.name === `wildlife-sightings:${name}` &&
|
|
entry.startTime >= warm[0].startTimeMs,
|
|
)
|
|
.reduce(
|
|
(sum, entry) =>
|
|
sum +
|
|
activeMs(
|
|
{
|
|
startTimeMs: entry.startTime,
|
|
durationMs: entry.duration,
|
|
},
|
|
collections,
|
|
),
|
|
0,
|
|
);
|
|
return [name, (duration / warm.length).toFixed(3)];
|
|
}),
|
|
);
|
|
t.diagnostic(
|
|
`6,144 cells + 500 observations, ${runs.at(-1).glowPrimitives} glow splats + ${runs.at(-1).billboards} real icons; moveEnd enqueue max=${enqueueMax.toFixed(3)}ms; cold max CPU slice=${coldMax.toFixed(3)}ms; all max CPU slice=${sliceMax.toFixed(3)}ms; warm total CPU median=${median(warmTotal).toFixed(3)}ms; warm slice p95=${percentile95(warmSlices.map((slice) => activeMs(slice, collections))).toFixed(3)}ms; raw wall slice max=${Math.max(...allSlices.map((slice) => slice.durationMs)).toFixed(3)}ms; observed GC pauses=${collections.length}; repeated Cartesian builds=0; CPU startup calibration=${runtimeSettleMs.toFixed(0)}ms, checksum=${calibrationChecksum} (cold fixture created afterward); warm phase mean ms=${JSON.stringify(phaseMeans)}`,
|
|
);
|
|
} finally {
|
|
h.destroy();
|
|
observer.disconnect();
|
|
}
|
|
},
|
|
);
|