Files
gods-eye-view/src/layers/wildlifeSightings/model.perf.test.mjs
T
Yehe LiuandClaude Opus 5.5 14f88b3e08 feat: Wildlife Sightings layer from iNaturalist and Acartia
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]>
2026-11-05 16:17:12 -05:00

77 lines
2.6 KiB
JavaScript

import assert from 'node:assert/strict';
import { performance } from 'node:perf_hooks';
import test from 'node:test';
import { perfBudgetTestOptions } from '../../../scripts/run-perf-tests.mjs';
import {
harness,
syntheticRows,
changePositions,
WILDLIFE_BENCHMARK_REFRESHES,
} from '../../testSupport/wildlifeBillboardModel.mjs';
// Pure model and incremental reconciliation, measured after warmup.
// The 2,000-contact allowance is a fraction of one 60Hz frame; the 5,000 cap
// gets a proportional allowance. No renderer, network or real sightings run.
const WILDLIFE_MODEL_UPDATE_BUDGET_MS = Object.freeze({
500: 4,
2000: 8,
5000: 20,
});
test(
'500 / 2,000 / 5,000 icon model updates stay within their named timing budgets',
perfBudgetTestOptions(),
(t) => {
// Warm the same pure hot paths before recording CPU time.
const warm = harness();
let warmRows = syntheticRows(2000);
warm.apply(warmRows);
for (let i = 0; i < 25; i++) {
warmRows = changePositions(warmRows, i);
warm.apply(warmRows);
}
for (const n of [500, 2000, 5000]) {
const h = harness();
let rows = syntheticRows(n);
const start = performance.now();
const initial = h.apply(rows);
const initialMs = performance.now() - start;
assert.equal(initial.created, n);
const durations = [];
for (let refresh = 0; refresh < WILDLIFE_BENCHMARK_REFRESHES; refresh++) {
rows = changePositions(rows, refresh);
const before = performance.now();
const update = h.apply(rows);
durations.push(performance.now() - before);
assert.deepEqual(update, {
created: 0,
removed: 0,
updated: n / 10,
writes: n / 10,
});
}
const meanMs =
durations.reduce((sum, value) => sum + value, 0) / durations.length;
const maxMs = Math.max(...durations);
assert.ok(
maxMs <= WILDLIFE_MODEL_UPDATE_BUDGET_MS[n],
`${n}: ${maxMs.toFixed(3)}ms update exceeds ${WILDLIFE_MODEL_UPDATE_BUDGET_MS[n]}ms`,
);
const before = { ...h.counters };
assert.deepEqual(h.apply([...rows].reverse()), {
created: 0,
removed: 0,
updated: 0,
writes: 0,
});
assert.deepEqual(
h.counters,
before,
'unchanged content performs zero billboard writes or allocations',
);
t.diagnostic(
`N=${n}; initial=${initialMs.toFixed(3)}ms; incremental10% mean=${meanMs.toFixed(3)}ms, max=${maxMs.toFixed(3)}ms; budget=${WILDLIFE_MODEL_UPDATE_BUDGET_MS[n]}ms; unchanged writes=0`,
);
}
},
);