perf(vessels): prune the AIS store on a timer and evict in insertion order

Every AIS position message walked both the vessel map and the pending-track
map to expire stale entries, and once the store was past its 50,000 cap it
also sorted every row to find the one to evict. The static-data map was never
pruned at all.

The expiry walk now runs on the existing 15 s AIS watchdog tick. Readers
already filtered rows by age; the track reader and the pending first fix now
check age too, so nothing expired is served between ticks. The vessel map is
re-inserted on update, which keeps it least recently updated first, so the
cap is enforced per message by dropping from the front. A vessel's static
entry goes when the vessel does, and static entries that never got a position
are held to the same cap.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Mazeyar Moeini FeizabadiandClaude Fable 5.2 committed 2026-11-13 14:43:43 +01:00
1 parent 188f0ccd9b
commit f47313ff3b
3 files changed
+237 -19

No files matched your search

+4
View File
@@ -10,6 +10,7 @@ import {
readAisTrack,
aisStreamRows,
newestAisPositionAt,
pruneAisStreamCache,
} from './ais-store.js';
// ---------------------------------------------------------------------------
// AISStream live vessel cache state
@@ -338,6 +339,9 @@ function startAisStreamWatchdogTick() {
} catch (error) {
console.warn('[AISStream] watchdog tick failed', error?.message || '');
}
// The store no longer prunes per message; this tick is its expiry clock,
// so a silent feed still releases vessels it stopped hearing from.
pruneAisStreamCache();
}, AISSTREAM_TICK_MS);
_aisStreamTickTimer.unref?.();
}