Skip to content

Fix sticky scroll performance issue by using correct array for min content width calculation #252342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 24, 2025

Sticky scrolling was causing noticeable performance issues and stuttering during scroll operations due to inefficient DOM queries in the StickyScrollWidget._renderRootNode method.

Problem

The _renderRootNode method was calculating _minContentWidthInPx using the old this._renderedStickyLines array instead of the newly built renderedStickyLines array. This caused:

  1. Performance degradation: Reading scrollWidth from potentially stale/removed DOM elements triggered unnecessary layout recalculations
  2. Incorrect calculations: Using outdated scroll width values from elements that were being removed from the DOM
  3. Browser frame drops: The additional layout work caused visible stuttering during scroll operations

Solution

Changed line 248 in stickyScrollWidget.ts to use the correct array and added proper empty array handling:

// Before (buggy):
this._minContentWidthInPx = Math.max(...this._renderedStickyLines.map(l => l.scrollWidth)) + layoutInfo.verticalScrollbarWidth;

// After (fixed):
this._minContentWidthInPx = renderedStickyLines.length > 0 
    ? Math.max(...renderedStickyLines.map(l => l.scrollWidth)) + layoutInfo.verticalScrollbarWidth 
    : 0;

Impact

  • Performance: Eliminates forced layout recalculations by using fresh scroll width values that were already computed during rendering
  • Accuracy: Ensures minimum content width calculation reflects the actual current DOM state
  • User Experience: Reduces scroll stuttering and frame drops when sticky scroll is enabled
  • Minimal Risk: Only 3 lines changed, preserving all existing functionality

The fix ensures that during sticky scroll updates, we use the scroll width values from the current rendering cycle instead of potentially accessing removed DOM elements.

Fixes #191973.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…ntent width calculation

Co-authored-by: aiday-mar <61460952+aiday-mar@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Sticky Scrolling Makes Scrolling Stutter Fix sticky scroll performance issue by using correct array for min content width calculation Jun 24, 2025
@Copilot Copilot AI requested a review from aiday-mar June 24, 2025 21:21
Copilot finished work on behalf of aiday-mar June 24, 2025 21:21
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.

Sticky Scrolling Makes Scrolling Stutter
2 participants