⚡ Bolt: Optimize WebGL loop to reduce GC and layout thrashing #54
Reference in New Issue
Block a user
Delete Branch "bolt-optimize-webgl-loop-6571928292931476466"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
⚡ Bolt: Optimize WebGL loop to reduce GC and layout thrashing
💡 What:
useRefholding immutable objects/arrays ({x,y},[x,y]) with mutable objects forpointerPosRefandmouseTargetRef.canvas.getBoundingClientRect()call inside therequestAnimationFrameloop that was causing synchronous layout thrashing whenrectRefwasn't immediately available.🎯 Why:
📊 Impact:
🔬 Measurement:
PR created automatically by Jules for task 6571928292931476466 started by @ragusa-it
👋 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
@jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!New to Jules? Learn more at jules.google/docs.
For security, I will only act on instructions from the user who triggered this task.
Pull request overview
This PR optimizes the WebGL animation loop in the GradientBlinds component to improve performance by reducing garbage collection pressure and eliminating layout thrashing. The changes replace immutable object allocations with mutable object updates and remove synchronous
getBoundingClientRect()calls from the animation loop.Changes:
mouseTargetReffrom array[x, y]to object{x, y}and updated all references to use property accesspointerPosReffrom nullable object to object withactiveboolean flag to track pointer state without creating new objectsgetBoundingClientRect()fallback calls from both the pointer event handler and the animation loop to prevent layout thrashingReviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@@ -373,11 +370,12 @@ void main() {if (factor > 1) factor = 1;const target = mouseTargetRef.current;const cur = uniforms.iMouse.value;The comment on line 332 states "Fallback: do nothing if rect is not ready yet to avoid sync layout thrashing", but the code actually does write to
mouseTargetRef.currentwith the values ofxandy, which are initialized to 0 on line 322. IfrectRef.currentis falsy, the coordinates will be set to (0, 0).This differs from the desktop path (line 349), which only updates
mouseTargetRef.currentwhen bothpointerPosRef.current.activeANDrectRef.currentare truthy. For consistency and to truly "do nothing" as the comment suggests, the mobile path should also guard the writes tomouseTargetRef.currentwith a check forrectRef.current.Pull request closed