Skip to content

[SR] Router marquee performance tweaks#5755

Closed
rgclayton wants to merge 1 commit intomainfrom
rm-performance-tweaks
Closed

[SR] Router marquee performance tweaks#5755
rgclayton wants to merge 1 commit intomainfrom
rm-performance-tweaks

Conversation

@rgclayton
Copy link
Copy Markdown
Contributor

@rgclayton rgclayton commented Apr 2, 2026

  • Reduce inertia during fast scrolling to avoid sustained RAF CPU usage
  • Pause auto rotation and video playing when scrolling the router marquee out of view. This also stop the background loading that continues to happen even when viewing content lower on the page.

For the 2nd bullet point open up dev tools network tab and watch the media.mp4's stop loading when the router marquee scrolls out of view. This was using extra cpu resources while scrolling down the page. The cpu seems to spin up less. Give it a look.

Details around the first bullet point:
How it works:

  • deltaY > 80 — threshold for “fast” scroll (a typical slow scroll is ~30–50, fast flick is 100+). Tune as needed.
  • lerp = 0.4 — during fast scroll, Lenis converges ~5x faster to the target position, so the RAF loop idles sooner instead of easing for hundreds of ms.
  • After 300ms of no fast-scroll events, lerp resets to the original smooth value.
  • Why this helps CPU: Lenis’s RAF loop runs on every frame until Math.abs(velocity) < threshold. With lerp = 0.08, a fast fling can keep it running for 1–2 seconds per gesture. At lerp = 0.4, it converges in a few frames.

Tuning knobs if needed:
Raise 80 threshold if it kicks in too eagerly on normal scrolling
Lower 0.4 toward 1.0 for even less inertia on fast scroll (1.0 = instant, no smoothing)

Raise 300 debounce if the smooth feel is snapping back too soon during continuous fast scroll

Test URLs:

@aem-code-sync
Copy link
Copy Markdown
Contributor

aem-code-sync bot commented Apr 2, 2026

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-sync branch
Commits

@narcis-radu narcis-radu added the do not merge PR should not be merged yet label Apr 2, 2026
Base automatically changed from site-redesign-foundation to main April 2, 2026 12:50
Copy link
Copy Markdown
Contributor

@JasonHowellSlavin JasonHowellSlavin left a comment

Choose a reason for hiding this comment

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

Were there any tests we could add? I see this is for c2, so not sure how that is set up.

Comment on lines +656 to +659
// Pause/resume based on scroll position. The router-marquee fills the viewport at
// the top of the page. Once the user has scrolled past half the viewport height,
// the block is considered offscreen. window.scrollY is reliable regardless of
// whether Lenis or native scroll is driving the animation.
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.

Did you want to keep these comments in? I know we tend to leave comments out if we can.

Comment on lines +673 to +675
// Lenis loads after blocks, so window.lenis isn't set at init() time.
// On the first native scroll event, swap to lenis.on() if available so
// subsequent visibility checks run inside Lenis's RAF loop.
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.

same here with these.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, notes for fast follow. Thank you!

let fastScrollTimer;
window.addEventListener('wheel', (e) => {
if (Math.abs(e.deltaY) > 70) {
window.lenis.options.lerp = 0.6;
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.

not sure here, but you mentioned above that lenis loads after blocks, so it might be good to optional chain here? Or check for window.lenis?

@rgclayton
Copy link
Copy Markdown
Contributor Author

Were there any tests we could add? I see this is for c2, so not sure how that is set up.

Thanks Jason! No, no C2 block as tests yet. This is for a test that will be going on the next month. We will have to circle back to address this. That's why comments are still in place for some follow up and knowledge.

@rgclayton
Copy link
Copy Markdown
Contributor Author

Closing for now. Will revisit while test is running.

@rgclayton rgclayton closed this Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge PR should not be merged yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants