Dev fixes 45% idle CPU drain in retro music app by reining in animation loops
A developer building a retro-themed music web app discovered that the browser tab was consuming 45% CPU and leaking roughly 15MB of memory per minute even when idle. Chrome DevTools profiling revealed that multiple canvas animation loops — powering dust particles, CRT scanlines, and an audio visualizer — were running at 60 frames per second regardless of whether music was paused or the tab was in the background. Compounding the problem, resizing the window or toggling modes stacked new requestAnimationFrame calls without cancelling the previous ones, while per-frame string allocations triggered constant garbage collection. The developer refactored the loops to pause whenever the tab is hidden or playback is stopped, using the browser's visibilitychange event and proper cleanup in React's useEffect. After the fix, idle CPU fell from 45% to under 1%, background-tab CPU dropped to zero, and memory usage stabilised.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in