Skip to content

⚡ bolt: [performance improvement]#17

Open
dttdrv wants to merge 1 commit intomainfrom
perf/cache-dimensions-scroll-11781990351487005585
Open

⚡ bolt: [performance improvement]#17
dttdrv wants to merge 1 commit intomainfrom
perf/cache-dimensions-scroll-11781990351487005585

Conversation

@dttdrv
Copy link
Copy Markdown
Owner

@dttdrv dttdrv commented Mar 16, 2026

💡 what: cached document.documentElement.scrollHeight and window.innerHeight within scrollprogress and sectionnav objects.
🎯 why: repeatedly querying dom properties like scrollheight and innerheight within scroll event listeners and intersection observer callbacks forces synchronous layout calculations, leading to layout thrashing and reduced rendering performance.
📊 impact: eliminates forced synchronous layouts during scrolling and intersection checking, maintaining a smoother 60fps experience, particularly noticeable on longer scrolls or lower-end devices.
🔬 measurement: run the frontend application and observe the performance timeline in devtools during scroll; forced layout recalculations related to scrollprogress and sectionnav will no longer appear. tests verified via node --test and a playwright script.


PR created automatically by Jules for task 11781990351487005585 started by @dttdrv

- cached `document.documentElement.scrollHeight` and `window.innerHeight` in `scrollprogress` and `sectionnav` to prevent forced synchronous layouts during active scroll events and intersection observer callbacks.
- implemented `resizeobserver` and tied into existing global debounced window resize handler to maintain layout accuracy.
- updated `.jules/bolt.md` with learnings on layout thrashing.
@google-labs-jules
Copy link
Copy Markdown

👋 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.

Copilot AI review requested due to automatic review settings March 16, 2026 05:49
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying personal-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6299288
Status: ✅  Deploy successful!
Preview URL: https://5af4c87b.personal-website-5ns.pages.dev
Branch Preview URL: https://perf-cache-dimensions-scroll.personal-website-5ns.pages.dev

View logs

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6299288ae9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread script.js
if (window.scrollY < 100) {
bestSection = this.sections[0]?.id;
} else if (window.scrollY + window.innerHeight >= document.documentElement.scrollHeight - 50) {
} else if (window.scrollY + this.cachedWindowHeight >= this.cachedDocHeight - 50) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recompute nav bounds when page height changes

SectionNav now relies on cachedDocHeight/cachedWindowHeight for the bottom-of-page override, but those caches are only refreshed in init() and on window resize; they are not updated when document height changes from normal runtime events (for example lazy-loaded images in index.html or other content expansion). In that case, handleIntersection compares window.scrollY against stale dimensions and can activate the last nav item too early or fail to activate it near the true bottom until a manual resize occurs.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Copilot AI left a comment

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 caches document.documentElement.scrollHeight and window.innerHeight in the ScrollProgress and SectionNav objects to avoid querying DOM layout properties during scroll handlers and IntersectionObserver callbacks, reducing layout thrashing.

Changes:

  • Added cachedDocHeight and cachedWindowHeight properties to ScrollProgress and SectionNav, with cacheDimensions() methods to refresh them.
  • Added a ResizeObserver in ScrollProgress.init() to keep cached values up to date when document dimensions change.
  • Added cacheDimensions() calls to the existing debounced window resize handler.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
script.js Caches scroll/window dimensions in ScrollProgress and SectionNav; adds ResizeObserver for ScrollProgress; updates resize handler.
.jules/bolt.md Documents the new caching convention for scroll-related DOM properties.

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

You can also share your feedback on Copilot code review. Take the survey.

Comment thread script.js
Comment on lines +1435 to +1436
// cache dimensions to prevent forced synchronous layouts during intersection observer callbacks
this.cacheDimensions();
Comment thread .jules/bolt.md
## 2024-05-16 - [Frontend Performance: Caching getBoundingClientRect in Animation Loops]
**Learning:** Frequent calls to `getBoundingClientRect()` inside `requestAnimationFrame` loops or scroll handlers (like in `MagneticLetters`, `MobileTouchRepel`, and `ParallaxLayers`) cause significant layout thrashing and forced synchronous layouts, degrading rendering performance.
**Action:** Always pre-calculate and cache document-relative element positions during initialization (`init()`). Update this cache on window resize events and after custom fonts load (using `document.fonts.ready.then()`). During active animations (`animate()`, `update()`, etc.), calculate viewport-relative positions using the cached document coordinates minus the current scroll offset (`window.scrollX` / `window.scrollY`) instead of directly querying the DOM. No newline at end of file
**Action:** Always pre-calculate and cache document-relative element positions during initialization (`init()`). Update this cache on window resize events and after custom fonts load (using `document.fonts.ready.then()`). During active animations (`animate()`, `update()`, etc.), calculate viewport-relative positions using the cached document coordinates minus the current scroll offset (`window.scrollX` / `window.scrollY`) instead of directly querying the DOM.\n## 2026-03-16 - [Frontend Performance: Caching scrollHeight and innerHeight in Scroll/IntersectionObserver loops]
Comment thread script.js
if (typeof MagneticLetters !== 'undefined') MagneticLetters.cachePositions();
if (typeof MobileTouchRepel !== 'undefined') MobileTouchRepel.cachePositions();
if (typeof ParallaxLayers !== 'undefined') ParallaxLayers.cachePositions();
if (typeof ScrollProgress !== 'undefined') ScrollProgress.cacheDimensions();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants