This article delves into the architectural challenges of rendering extremely large pull requests within the GitHub Copilot app, focusing on maintaining UI performance and responsiveness. It highlights how the unpredictable nature of comment heights breaks traditional virtualization techniques and describes a hybrid geometry approach to manage deterministic code lines and dynamic comment blocks effectively. The solution involves a carefully designed measurement scheduler and scroll anchoring to prevent UI jank.
Read original on GitHub EngineeringThe core problem addressed by GitHub Engineering in the Copilot app is rendering pull requests that are
Traditional UI virtualization relies on knowing element heights upfront to calculate scrollbar dimensions and positions efficiently. For code diffs, where each line has a consistent height, this "all heights known before paint" contract works well. However, integrating dynamic content like review comments, whose heights vary based on markdown rendering, user interactions (expanding/collapsing sections, typing replies), and image loading, breaks this contract. Estimating heights leads to visual artifacts like whitespace gaps or clipped content, and updating heights after render causes jarring scroll jumps.
To overcome the limitations of a single geometry, GitHub Copilot adopted a hybrid approach by splitting the document's total height into two independent domains:
A crucial innovation is the single idle- and scroll-gated measurement pass, replacing per-block ResizeObservers which caused feedback loops. This pass:
To prevent scroll jumps when heights change, a scroll anchoring mechanism corrects by *identity* rather than *pixel position*. It captures the user's anchored element (row or block) and its offset, applies height deltas, and then repositions the viewport to keep the anchor stable. Special rules are applied for changes above/below the viewport, direct user interactions, and to avoid fighting active scroll momentum, ensuring a smooth user experience even with significant layout changes.