From 6905b7a410aa28d5fa6bbbaa8df35798a905535e Mon Sep 17 00:00:00 2001 From: MystiPanda Date: Wed, 8 May 2024 22:33:13 +0800 Subject: [PATCH] perf: Limit drawing frame rate --- src/components/layout/traffic-graph.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/layout/traffic-graph.tsx b/src/components/layout/traffic-graph.tsx index 5c1a6b7e..660d6298 100644 --- a/src/components/layout/traffic-graph.tsx +++ b/src/components/layout/traffic-graph.tsx @@ -147,6 +147,10 @@ export const TrafficGraph = forwardRef((props, ref) => { const now = Date.now(); const diff = now - lastTime; + if (diff < 33) { + raf = requestAnimationFrame(() => drawGraph(lastTime)); + return; + } const temp = Math.min((diff / 1000) * dx + countRef.current, dx); const offset = countRef.current === 0 ? 0 : temp; countRef.current = temp;