Przeglądaj źródła

perf: Limit drawing frame rate

MystiPanda 1 rok temu
rodzic
commit
e520be80c0
1 zmienionych plików z 4 dodań i 0 usunięć
  1. 4 0
      src/components/layout/traffic-graph.tsx

+ 4 - 0
src/components/layout/traffic-graph.tsx

@@ -147,6 +147,10 @@ export const TrafficGraph = forwardRef<TrafficRef>((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;