perf(traffic): single-slice snapshots with worker-side aging

The traffic pipeline re-rendered twice per second (worker snapshot
plus a 1 s now-tick), cloned the 10-minute and 60-minute arrays
through every snapshot, and re-filtered them on the main thread.
Snapshots now carry only the range slice the graph renders, a 1 s
worker-side heartbeat re-broadcasts only when points age out of the
window, and snapshot ingestion pauses while the window is hidden.
Perf harness A/B: hidden-phase webview CPU 2.45% -> 0.77%, main
0.90% -> 0.37%, webview RSS about -3 MB; visible phases unchanged.
This commit is contained in:
Tunglies
2026-09-11 13:19:50 +08:00
parent 2a975d546e
commit 38c54c5b3b
5 changed files with 70 additions and 81 deletions
+23 -1
View File
@@ -24,6 +24,29 @@ export const formatTrafficName = (timestamp: number) => {
)}`
}
export const isSameTrafficData = (
current: ITrafficDataPoint[],
next: ITrafficDataPoint[],
) => {
if (current === next) return true
if (current.length !== next.length) return false
for (let i = 0; i < current.length; i++) {
const currentPoint = current[i]
const nextPoint = next[i]
if (
currentPoint.timestamp !== nextPoint.timestamp ||
currentPoint.up !== nextPoint.up ||
currentPoint.down !== nextPoint.down
) {
return false
}
}
return true
}
export class TrafficDataSampler {
private rawBuffer: ITrafficDataPoint[] = []
private rawHead = 0
@@ -125,7 +148,6 @@ export class TrafficDataSampler {
up: p.up,
down: p.down,
timestamp: p.timestamp,
name: formatTrafficName(p.timestamp),
}))
return [...compressedData, ...rawData].sort(