perf: optimize canvas rendering loops and options change checks - #17
Merged
DavidHDev merged 1 commit intoJul 26, 2026
Merged
Conversation
- Pause requestAnimationFrame loops in hero-reel and hero-reveal when scrolled out of view or tab is hidden - Dynamically toggle WebGL setAnimationLoop (start/stop) on visibility changes for GlassObject, DitheredObject, and ParticleObject - Add shallow comparison for primitive configuration properties in setOptions to prevent redundant WebGL/Three.js updates on re-render
Owner
|
Really nice, thanks for the improvements. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR implements performance optimizations to reduce idle CPU/GPU consumption and avoid redundant calculations/re-renders during parent component updates:
Dynamic Animation Loop Control (Viewport & Tab Visibility):
HeroReel(hero-reel.tsx) andHeroReveal(hero-reveal.tsx) to pause theirrequestAnimationFrameloops when the components scroll out of the viewport (usingIntersectionObserver) or when the browser tab is hidden (using the documentvisibilitychangeevent).GlassObjectVanilla,DitheredObjectVanilla, andParticleObjectVanilla. Instead of running an empty animation loop insiderenderer.setAnimationLoopwhen out of view, the loop is completely halted (setAnimationLoop(null)) and resumed dynamically.Redundant Options Updates Elimination (Shallow Parameter Checks):
setOptions(next)inside WebGL vanilla files to perform shallow parameter checks on primitive properties (filtering out React callback functions likeonLoadoronError).Performance Comparison
Measurements were taken using Chrome DevTools (Performance Monitor) on idle state (scrolled down below the fold, rendering elements out of view):
requestAnimationFrameVerification Steps (How to review)
npm run dev.F12), click More Tools -> Performance monitor./) and scroll down to the bottom./playground), open the controls drawer, and change any option.No CSS or styling classes were altered.
Type of change
Checklist