一句话:提出多语言静态分析框架与自动审批器,判定代码 diff 是否仅含不改变行为的改动。
大规模项目每天提交大量代码变更,人工审查耗时耗资源,但其中不少 diff 仅包含格式调整、变量/函数重命名、常量提取等不改变系统行为的语法修改。本文提出面向 Go 和 Java 的多语言自动代码批准器 Last Diff Analyzer,用于检测一个可审查的增量代码变更单元(diff)是否只包含不修改系统行为的改动。其核心是一个新型多语言静态分析框架,统一多语言的共有特性,同时隔离各语言独有构造,从而便于扩展到 TypeScript、Kotlin、Swift 等语言。除跳过不必要的人工审查外,该工具还可用于跳过自动批准 diff 对应的资源密集型端到端(E2E)测试。该分析器已在 Uber 规模化部署,生产数据显示每周约 15% 的被分析 diff 被自动批准用于代码审查;同时,跳过 E2E 测试使专用于 E2E 测试的服务器节点用量(按执行的 E2E 测试数计)相比未启用时降低 13.5%。
Code review is a crucial step in ensuring the quality and maintainability of software systems. However, this process can be time-consuming and resource-intensive, especially in large-scale projects where a significant number of code changes are submitted every day. Fortunately, not all code changes require human reviews, as some may only contain syntactic modifications that do not alter the behavior of the system, such as format changes, variable / function renamings, and constant extractions. In this paper, we propose a multi-language automated code approver — Last Diff Analyzer for Go and Java, which is able to detect if a reviewable incremental unit of code change (diff) contains only changes that do not modify system behavior. It is built on top of a novel multi-language static analysis framework that unifies common features of multiple languages while keeping unique language constructs separate. This makes it easy to extend to other languages such as TypeScript, Kotlin, Swift, and others. Besides skipping unnecessary code reviews, Last Diff Analyzer could be further applied to skip certain resource-intensive end-to-end (E2E) tests for auto-approved diffs for significant reduction of resource usage. We have deployed the analyzer at scale within Uber, and data collected in production shows that approximately 15% of analyzed diffs are auto-approved weekly for code reviews. Furthermore, 13.5% reduction in server node usage dedicated to E2E tests (measured by number of executed E2E tests) is observed as a result of skipping E2E tests, compared to the node usage if Last Diff Analyzer were not enabled.
@inproceedings{WangWCC23,
title = {Last Diff Analyzer: Multi-language Automated Approver for Behavior-Preserving Code Revisions},
author = {Yuxin Wang and Adam Welc and Lazaro Clapp and Lingchao Chen},
booktitle = {FSE},
year = {2023},
doi = {10.1145/3611643.3613870}
}