Technology
GitHub Optimizes Copilot Diff Viewer to Handle Million-Line Pull Requests Smoothly
GitHub's Copilot app was rebuilt to render massive code diffs—including a test case with over a million changed lines—without performance degradation, addressing a bottleneck where AI code generation now outpaces human code review.
InfoQ
GitHub engineering has tackled a fundamental challenge in modern code review: as AI agents generate increasingly large pull requests, the ability to review them has become the bottleneck rather than the ability to write them. The company's solution, detailed by Principal Design Engineer Alberto Gimeno, involved a ground-up rebuild of how the Copilot app renders diffs for massive changesets.
The Challenge: Code at Scale#
The test case illustrates the scale of the problem—a pull request spanning 2,200 files with over a million changed lines and more than 400 inline review comments. Traditional approaches to rendering such a diff would create a janky, unresponsive interface. The underlying issue is that AI coding tools are now producing pull requests far faster than teams can meaningfully review them.
A New Architecture for Variable Content#
The key insight behind the rebuild was recognizing that pull requests are not uniform lists. Code rows have predictable dimensions—fixed height at a known font size—so their geometry can be precomputed and remain stable. Comments, by contrast, are unpredictably dynamic: markdown bodies reflow based on width, collapsible sections toggle in place, reply composers expand as users type, and images change height on load.
Rather than force a single virtualizer to manage both fixed and variable-height content, the team split the rendering into two independent systems:
total height = deterministic code height
+ Σ dynamic block effective heights
+ scroll padding
Dynamic blocks are keyed by identity (file, line, side) rather than pixel position, with a fingerprint tracking content state, open/closed toggles, and measurement width. A single measurement pass runs at idle, reading mounted blocks in one batch within roughly 2,400 pixels of the viewport. Critically, scroll corrections anchor to the user's current view, preventing the interface from fighting active scrolling.
Learning from an Early Mistake#
Gimeno openly discusses an initial misstep: the first approach used one ResizeObserver per block to write height changes directly back into the layout—a classic feedback loop whose cost multiplies with every mounted element. The final solution keeps the observers but defaults them to flagging rather than writing. The system makes a deliberate exception when the user toggles a collapsible section or expands a reply composer, ensuring content below moves in the same frame, preserving the visual connection between user action and layout response.

