在 GitHub Copilot 应用程序中呈现巨大的拉取请求
我们如何在 GitHub Copilot 应用程序中重建 diff 界面,以打开包含数百条内联审核评论的百万行拉取请求。在 GitHub Copilot 应用程序中渲染巨大的拉取请求一文首先出现在 GitHub 博客上。

来自 GitHub AI 的官方动态,版本与适用范围以发布方说明为准。
GitHub AI · 查看官方发布中文机器翻译 · 原文附后
正文 · 来源原文
首席设计工程师
广泛的重构和迁移通常必须作为一项变更来实施。
堆叠拉取请求是将工作拆分为更小的更改的好方法,这使得审查更容易,并帮助团队降低风险。但有些变化,比如这个,不能完全分开。这给你留下了一个可能变得非常大的拉取请求,而审查对话会导致它增长。
即使差异及其对话巨大,审阅体验也需要保持快速和流畅。在 GitHub Copilot 应用程序中,我们根据该要求重建了拉取请求视图。
为了看看能走多远,我们提出了我们能找到的最大的拉取请求:一个开源请求,包含 2,200 个文件、超过一百万行的更改行以及超过 400 条内联审核评论。以下是我们如何使这种极端的拉取请求变得高性能。
问题的范围
快速渲染大差异是很好理解的:虚拟化行,保持安装的 DOM 小,并依靠每行都是已知高度的一行代码这一事实。
评论是最难的部分。评论的高度取决于其降价方式、可扩展部分、是否有回复框以及图像是否已加载。您可以在渲染时发现所有这些。这迫使我们采用不同的架构。
三个问题:
测量。在渲染之前,您无法知道评论有多高。这打破了让大差异在滚动时保持响应的设计。数据管道。如果提供给它的数据管道停止,或者如果它丢弃了已经完成的工作,那么快速差异表面就没有价值。我们实际上是如何发现错误的。这些问题在负载下、在特定引擎上、在特定滚动位置处显现出来。因此,我们定义了健康的含义,对表面进行检测来回答它,并在无人值守的情况下运行整个变更→测量→改进循环。
第 1 部分:虚拟化,以及为什么评论会破坏它
第一步是了解使仅代码差异快速进行的几何结构。一旦评论出现,几何图形就不再足够了。
是什么让大差异变得更快
您无法在一个页面上放置一百万个 DOM 节点。标准答案是虚拟化:仅安装屏幕上的行,加上一个小边距,并在用户滚动时回收这些相同的 DOM 元素。该列表的行为就像所有百万行都存在一样。滚动条大小合适,滚动到行有效。但同时只有大约 100 行是真实的。
为了维持这种错觉,必须有某种东西来提供几何形状。滚动条高度是所有行高度的总和。第 N 行的位置是其上方各行高度的总和。跳到一行,绘制滚动条,决定屏幕上显示的内容,这都是高度表上的算术。您可以根据估计构建该表,并在测量行时对其进行更正,通用可变高度虚拟器正是这样做的。
但如果每一行都是已知字体大小的一行代码,则不必这样做。您可以预先计算整个表格,并且它永远不会改变,因此以后无需更正。
将此称为“油漆前已知的所有高度”合同。我们的 diff 表面是围绕它构建的:
一个命令式的、回收的代码行渲染器(每行没有 React 组件) 用于偏移数学的类型化数组几何图形 后端拥有的 diff 文档流结构优先 具有精确“滚动到第 N 行”的命令式滚动 API
查看英文原文
Rendering huge pull requests in the GitHub Copilot app
How we rebuilt the diff surface in the GitHub Copilot app to open a million-line pull request with hundreds of inline review comments. The post Rendering huge pull requests in the GitHub Copilot app appeared first on The GitHub Blog .
正文 · 来源原文
Principal Design Engineer
Broad refactors and migrations often have to land as one change.
Stacked pull requests are a great way to split work into smaller changes, which makes reviews easier and helps teams ship with less risk. But some changes, like this one, can’t be split cleanly. That leaves you with a single pull request that can get very large, and the review conversation causes it to grow.
The review experience needs to remain fast and smooth even when the diff and its conversation are enormous. In the GitHub Copilot app, we rebuilt the pull request view with that requirement in mind.
To see how far that goes, we opened the biggest pull request we could find: an open source one with 2,200 files, over a million changed lines, and more than 400 inline review comments. Here’s how we made even this extreme pull request performant.
The scope of the problem
Rendering a large diff at speed is well-understood: virtualize the rows, keep the mounted DOM small, and lean on the fact that every row is a line of code at a known height.
Comments are the hard part. A comment’s height depends on how its markdown wraps, the expandable sections, whether there’s a reply box in it, and whether its images have loaded yet. You find all of that out at render time. This forces a different architecture.
