MCPcopy Create free account
hub / github.com/codeaashu/claude-code / monitorScrollFps

Function monitorScrollFps

web/lib/performance/metrics.ts:147–176  ·  view source on GitHub ↗
(element: HTMLElement)

Source from the content-addressed store, hash-verified

145
146/** Monitor scroll FPS during user scrolling. Returns a cleanup fn. */
147export function monitorScrollFps(element: HTMLElement): () => void {
148 let frameCount = 0;
149 let lastTime = performance.now();
150 let rafId: number;
151 let scrolling = false;
152
153 const onScroll = () => { scrolling = true; };
154
155 const loop = () => {
156 rafId = requestAnimationFrame(loop);
157 if (!scrolling) return;
158 frameCount++;
159 const now = performance.now();
160 if (now - lastTime >= 1000) {
161 const fps = (frameCount / (now - lastTime)) * 1000;
162 report({ name: "scroll_fps", value: fps, rating: fps >= 55 ? "good" : fps >= 30 ? "needs-improvement" : "poor" });
163 frameCount = 0;
164 lastTime = now;
165 scrolling = false;
166 }
167 };
168
169 element.addEventListener("scroll", onScroll, { passive: true });
170 rafId = requestAnimationFrame(loop);
171
172 return () => {
173 cancelAnimationFrame(rafId);
174 element.removeEventListener("scroll", onScroll);
175 };
176}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected