提升 diff 行性能的艰难历程
Pull requests are the beating heart of GitHub. As engineers, this is where we spend a good portion of our time. And at GitHub’s scale—where pull requests can range from tiny one-line fixes to changes spanning thousands of files and millions of lines—the pull request review experience has to stay fast and responsive.
Pull request 是 GitHub 的核心。作为工程师,我们大部分时间都在这里度过。而在 GitHub 的规模下——pull request 的范围可以从微小的一行代码修复到跨越数千个文件和数百万行代码的更改——pull request 的审查体验必须保持快速和响应灵敏。
We recently shipped the new React-based experience for the Files changed tab (now the default experience for all users). One of our main goals was to ensure a more performant experience across the board, especially for large pull requests. That meant investing in, and consistently prioritizing, the hard problems like optimized rendering, interaction latency, and memory consumption.
我们最近发布了基于 React 的全新 Files changed 标签页体验(现已成为所有用户的默认体验)。我们的主要目标之一是确保全面提升性能体验,尤其是针对大型 pull request。这意味着我们需要投入精力并始终优先解决优化渲染、交互延迟和内存消耗等难题。
For most users before optimization, the experience was fast and responsive. But when viewing large pull requests, performance would noticeably decline. For example, we observed that in extreme cases, the JavaScript heap could exceed 1 GB, DOM node counts surpassed 400,000, and page interactions became extremely sluggish or even unusable. Interaction to Next Paint (INP) scores (a key metric in determining responsiveness) were above acceptable levels, resulting in an experience where users could quantifiably feel the input lag.
在优化之前,对大多数用户而言,体验是快速且响应迅速的。但在查看大型 pull request 时,性能会明显下降。例如,我们观察到在极端情况下,JavaScript 堆内存可能超过 1 GB,DOM 节点数超过 400,000,页面交互变得极其缓慢甚至无法使用。Interaction to Next Paint(INP)得分(决定响应速度的关键指标)高于可接受水平,导致用户能明显感觉到输入延迟。
Our recent improvements to the Files changed tab have meaningfully improved some of these core performance metrics. While we covered several of these changes briefly in a recent changelog, we’re going to cover them in more detail here. Read on for why they mattered, what we measured, and how those updates improved responsiveness and me...