Skip to content

chore: optimize tilt animation by skipping offscreen updates inside hero-glass.js#208

Open
Katotodan wants to merge 4 commits into
meshery-extensions:masterfrom
Katotodan:chore/hero-glass
Open

chore: optimize tilt animation by skipping offscreen updates inside hero-glass.js#208
Katotodan wants to merge 4 commits into
meshery-extensions:masterfrom
Katotodan:chore/hero-glass

Conversation

@Katotodan

Copy link
Copy Markdown
Contributor

Notes for Reviewers
This PR improves the performance and execution flow of the tilt interaction system by reducing unnecessary computations when the hero section is not visible.

Key Changes

  • Added early exit in updateScene() when the hero element is not in view
    • Prevents unnecessary layout reads (getBoundingClientRect) and style updates
  • Improved integration with IntersectionObserver to control when updates should run
  • Removed initial unconditional updateScene() call in favor of event-driven updates
  • Simplified observer logic and ensured updates are scheduled on visibility changes

Performance Impact

  • Reduces layout thrashing and CPU usage when the hero section is offscreen
  • Avoids redundant animation frame work when not needed

Note

No UI change is visible after this modification.

Signed commits

  • Yes, I signed my commits.

Signed-off-by: DANIEL KATOTO <katotodan@gmail.com>
Signed-off-by: DANIEL KATOTO <katotodan@gmail.com>
@github-actions

github-actions Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

🚀 Preview deployment: https://meshery-extensions.github.io/kanvas-site/pr-preview/pr-208/

Note: Preview may take a moment (GitHub Pages deployment in progress). Please wait and refresh. Track deployment here

@Katotodan

Copy link
Copy Markdown
Contributor Author

The script had also scroll even listener on the widow, which were been called and update the pointer and also call the updateScene() function. Without the added check, a for loop was running every time we scroll on the page.
This PR fixes also that.

@Bhumikagarggg

Copy link
Copy Markdown
Contributor

@Katotodan Thank you for your contribution! Let's discuss this during the website call tomorrow at 5:30 PM IST | 7 AM CST Add it as an agenda item to the meeting minutes, if you would 🙂

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to reduce unnecessary work in the hero-glass.js tilt interaction loop by stopping scene updates when the hero section is not visible, relying more on IntersectionObserver-driven scheduling.

Changes:

  • Adds an early return in updateScene() when #hero is missing or not intersecting.
  • Simplifies IntersectionObserver flow and schedules updates on visibility changes.
  • Removes the unconditional initial updateScene() call in favor of event-driven updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread static/scripts/hero-glass.js Outdated
Comment thread static/scripts/hero-glass.js
Comment thread static/scripts/hero-glass.js Outdated
Comment thread static/scripts/hero-glass.js Outdated
Comment thread static/scripts/hero-glass.js Outdated
Signed-off-by: DANIEL KATOTO <katotodan@gmail.com>

@Bhumikagarggg Bhumikagarggg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve conflicts.

@Bhumikagarggg

Copy link
Copy Markdown
Contributor

@Katotodan Thank you for your contribution! Let's discuss this during the website call tomorrow at 5:30 PM IST | 7 AM CST Add it as an agenda item to the meeting minutes, if you would 🙂

Signed-off-by: APIPAWE KATOTO <katotodan@gmail.com>
}
const relX = (pointer.x - heroRect.left) / heroRect.width - 0.5;
const relY = (pointer.y - heroRect.top) / heroRect.height - 0.5;
const clampedX = Math.max(-0.5, Math.min(0.5, relX));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing clampedX and clampedY, which can allow excessive tilt when the pointer is far from the hero area. The optimization should skip updates when the hero is offscreen, but the tilt values should still stay clamped. please revert 37 and 38 line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants