mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-21 19:52:12 +08:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user