paperbot · PL 论文追踪

全部论文 待读 收藏

BDiff: Block-Aware and Accurate Text-Based Code Differencing

BDiff:块感知且准确的基于文本的代码差分
ASE Proceedings of the 41st IEEE/ACM International Conference on Automated Software Engineering2026引用 0 inbox
Yao Lu, Wanwei Liu, Tanghaoran Zhang, Kang Yang, Yang Zhang, Wenyu Xu, Longfei Sun, Xinjun Mao, Shuzheng Gao, Michael R. Lyu
crossref: 2026-10-09

AI 速览

一句话:提出 BDiff,一种能识别块级与行级编辑动作的文本差分算法,生成更贴近开发者意图的最小编辑脚本。

传统行级差分工具(如 Git 的 Myers 算法)无法准确识别块移动、块复制等块级编辑动作,会把多行块编辑拆成碎片化的行级变更,增加代码评审的认知负担。BDiff 在传统差分算法基础上,先构造包含所有可能行映射与块映射的候选集合,再利用 Kuhn-Munkres 算法求解最优映射集,从而导出与开发者原始意图高度一致的最小编辑脚本,支持两类块级编辑动作与五类行级编辑动作。评估方面,作者选取五个当前最优工具(含大语言模型)作为基线,采用定性与定量结合的方法,从编辑脚本大小、结果质量和运行时间三个维度进行比较。实验表明 BDiff 的差分结果质量优于基线工具,且运行时间具有竞争力;同时实验揭示了大语言模型在代码差分任务上的不可靠性及其在运行效率上的不可行性。基于该算法,作者还实现了一个开源的可视化差分工具。

问题
现有行级差分工具无法识别块移动、块复制等块级编辑动作,将多行块编辑碎片化为行级变更,增加代码评审负担。
方法
在传统差分算法之上构造所有可能的行映射与块映射候选集,用 Kuhn-Munkres 算法求最优映射集并导出最小编辑脚本,支持两类块级与五类行级编辑动作。
评估
以五个最先进工具(包括大语言模型)为基线,用定性与定量结合的方式,从编辑脚本大小、结果质量与运行时间三方面对比评估,并实现了开源可视化差分工具。
原文摘要(Abstract)

Code differencing is a fundamental technique in software engineering. Traditional line-level differencing tools (e.g., Git Myers algorithm) cannot accurately identify block-level edit actions (EAs) such as block move and copy, which are common in real development. They split multi-line block edits into fragmented line-wise changes, raising developers’ cognitive overhead during code review. This paper presents BDiff, a text-based differencing algorithm capable of identifying two types of block-level EAs and five types of line-level EAs. Building on traditional differencing algorithms, we first construct a candidate set containing all possible line and block mappings. Leveraging the Kuhn-Munkres algorithm, we then compute the optimal mapping set and derive a minimal edit script (ES) that closely aligns with the original developer intent. To evaluate BDiff, we selected five state-of-the-art tools, including large language models (LLMs), as baselines, and adopted a combined qualitative and quantitative approach to assess their performance in terms of ES size, result quality, and running time. Experimental results show that BDiff produces higher-quality differencing results than baseline tools while maintaining competitive runtime performance. Our experiments also show the unreliability of LLMs in code differencing tasks and their infeasibility in terms of runtime efficiency. Based on the proposed algorithm, we have implemented an open-sourced visual differencing tool.

链接与引用

DOI 原文 · arXiv · DBLP

BibTeX
@inproceedings{abs-2510-21094,
  title = {BDiff: Block-Aware and Accurate Text-Based Code Differencing},
  author = {Yao Lu and Wanwei Liu and Tanghaoran Zhang and Kang Yang and Yang Zhang and Wenyu Xu and Longfei Sun and Xinjun Mao and Shuzheng Gao and Michael R. Lyu},
  booktitle = {ASE},
  year = {2026},
  doi = {10.1145/3832783.3837431}
}