mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-23 13:02:18 +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:
@@ -20,6 +20,7 @@ import {
|
||||
formatTrafficHourMinute,
|
||||
formatTrafficMinuteSecond,
|
||||
formatTrafficName,
|
||||
isSameTrafficData,
|
||||
} from '@/utils/traffic-sampler'
|
||||
|
||||
interface ITrafficItem {
|
||||
@@ -84,29 +85,6 @@ interface EnhancedCanvasTrafficGraphProps {
|
||||
ref?: Ref<EnhancedCanvasTrafficGraphRef>
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
const displayDataReducer = (
|
||||
current: ITrafficDataPoint[],
|
||||
payload: ITrafficDataPoint[],
|
||||
|
||||
Reference in New Issue
Block a user