⚡ [Performance] Fix Canvas Animation Memory Leak in BiologyView#2
⚡ [Performance] Fix Canvas Animation Memory Leak in BiologyView#2Sir-Ripley wants to merge 1 commit intomainfrom
Conversation
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR fixes a memory/CPU leak in BiologyView’s canvas animation loop by ensuring the requestAnimationFrame ID is tracked across all recursive frames and properly cancelled on unmount. Sequence diagram for updated BiologyView canvas animation lifecyclesequenceDiagram
participant BiologyView
participant Browser
BiologyView->>Browser: requestAnimationFrame(anim)
Browser-->>BiologyView: id0
BiologyView->>Browser: store id0 in id
loop On_each_frame
BiologyView->>Browser: requestAnimationFrame(anim)
Browser-->>BiologyView: idN
BiologyView->>Browser: update id with idN
end
BiologyView-->>Browser: cancelAnimationFrame(id) on unmount_or_rerender
alt Previous_behavior
note over BiologyView,Browser: id was const and not updated inside anim
BiologyView-->>Browser: cancelAnimationFrame(stale_id)
Browser-->>BiologyView: newest animation loop continues running
else New_behavior
note over BiologyView,Browser: id is let and updated on each frame
BiologyView-->>Browser: cancelAnimationFrame(current_id)
Browser-->>BiologyView: active animation loop is stopped
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
❌ Deploy Preview for qag-oracle failed.
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
💡 What:
Updated the animation frame loop inside the useEffect of
components/BiologyView.tsxto re-assign theidvariable on eachrequestAnimationFramecall.🎯 Why:
Previously,
idwas assigned only once and did not track subsequent frames created within theanimfunction. When the component unmounted or re-rendered,cancelAnimationFramereceived an outdated or invalid ID, leaving the newest recursiverequestAnimationFrameloop running indefinitely. This caused a memory and CPU leak where orphaned animation loops piled up over multiple renders.📊 Measured Improvement:
Because this involves React's unmount/re-render lifecycle and orphaned browser animation frames, standard runtime profiling of a single cycle doesn't capture the compounding leak. The change acts as a structural prevention mechanism (O(1) loops vs O(n) loops per render), eliminating the infinite growth of unmanaged callbacks and the associated continuous UI thread tax, which directly bounds CPU overhead to the single active component instance.
PR created automatically by Jules for task 3510052348411773146 started by @Sir-Ripley
Summary by Sourcery
Bug Fixes: