perf(cluster): cache the worked-index and bound the spot-status cache (RBN firehose)
A user on a slow PC with RBN saw OpsLog at 94% CPU and 8.5 GB RAM (Logger32: 3%
/ 34 MB on the same feeds). Two runaway costs under the spot firehose:
- ClusterSpotStatuses re-scanned the ENTIRE logbook (5-6 full-table maps) on
every 50 ms spot batch — ~20×/second — its "one scan regardless of batch" doc
was untrue. On a big log that's millions of row-scans/second → the pegged CPU.
Now cached in clusterStatusCache (an immutable snapshot), rebuilt only when the
logbook changes (noteWorked on a single log, invalidateAwardStats on bulk), so
it's one scan per logged QSO instead of per batch.
- The frontend spotStatus map had no cap: one entry per call|band|mode ever seen,
and RBN produces thousands of unique calls/hour → unbounded growth to GBs, plus
a full {...prev} copy 20×/second. Now pruned back to the live (SPOTS_CAP=1000)
spots once it drifts past 2×, with a cheap same-reference bail-out otherwise.
This commit is contained in:
@@ -1504,6 +1504,22 @@ export default function App() {
|
||||
// a stale closure.
|
||||
const spotsRef = useRef(spots);
|
||||
useEffect(() => { spotsRef.current = spots; }, [spots]);
|
||||
// Bound the status cache. Keyed per call|band|mode, it otherwise kept an entry
|
||||
// for every station ever seen — under an RBN firehose (thousands of unique
|
||||
// calls/hour) that grew without limit to gigabytes. Prune it back to the live
|
||||
// (SPOTS_CAP-limited) spots once it drifts well past them. The size check bails
|
||||
// cheaply the rest of the time (returning the same reference, so no dependent
|
||||
// memo re-runs); an evicted spot is just re-resolved if it reappears.
|
||||
useEffect(() => {
|
||||
setSpotStatus((prev) => {
|
||||
const keys = Object.keys(prev);
|
||||
if (keys.length <= SPOTS_CAP * 2) return prev;
|
||||
const live = new Set(spots.map((x) => spotStatusKey(x.dx_call, x.band ?? '', x.comment ?? '', x.freq_hz)));
|
||||
const pruned: typeof prev = {};
|
||||
for (const k of keys) if (live.has(k)) pruned[k] = prev[k];
|
||||
return pruned;
|
||||
});
|
||||
}, [spots]);
|
||||
// Re-fetch the status of every SHOWN spot and OVERWRITE the cache (merge, never
|
||||
// clear). Overwriting keeps the other NEW badges on screen until their fresh
|
||||
// value lands, instead of blanking the whole grid and letting the badges pop
|
||||
|
||||
Reference in New Issue
Block a user