arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2510.21094cs.SE
收藏

BDiff:块感知且精确的基于文本的代码差异比较

BDiff: Block-aware and Accurate Text-based Code Differencing

National University of Defense Technology(国防科技大学);The Chinese University of Hong Kong(香港中文大学)

Yao Lu, Wanwei Liu, Tanghaoran Zhang, Kang Yang, Yang Zhang, Wenyu Xu, Longfei Sun, Xinjun Mao, Shuzheng Gao, Michael R. Lyu

AI总结:

针对现有文本差异工具无法有效识别跨行块级编辑的问题,提出BDiff算法,利用Kuhn-Munkres算法优化映射以最小化编辑脚本,实验证明其生成结果优于现有工具及大语言模型。

摘要:

代码差异比较是软件工程实践与研究中的一项基础技术。尽管在过去十年中,研究人员提出了能够识别行级变更的基于文本的差异比较技术,但现有方法在识别作用于跨多行文本块的编辑操作(EAs)方面存在显著局限。此类编辑操作在开发者的实践中很常见,例如移动代码块以实现条件分支,或复制方法定义块以实现重载。现有工具将此类块级操作表示为离散的行级编辑操作序列,迫使开发者手动关联它们,从而显著阻碍了变更理解的效率。为解决此问题,我们提出了BDiff,一种基于文本的差异比较算法,能够识别两种类型的块级编辑操作和五种类型的行级编辑操作。在传统差异比较算法的基础上,我们首先构建一个包含所有可能的行映射和块映射的候选集。利用Kuhn-Munkres算法,我们随后计算最优映射集,该映射集能够最小化编辑脚本(ES)的大小,同时紧密贴合开发者的原始意图。为验证BDiff的有效性,我们选取了五个最先进的工具(包括大型语言模型(LLMs))作为基线,并采用定性与定量相结合的方法,从编辑脚本大小、结果质量和运行时间三个方面评估其性能。实验结果表明,BDiff在保持具有竞争力的运行时间性能的同时,生成了比基线工具更高质量的差异比较结果。我们的实验还揭示了LLMs在代码差异比较任务中结果质量的不可靠性以及运行时间效率方面的不可行性。我们已实现了一个基于Web的可视化差异比较工具。

英文摘要:

Code differencing is a fundamental technique in software engineering practice and research. While researchers have proposed text-based differencing techniques capable of identifying line changes over the past decade, existing methods exhibit a notable limitation in identifying edit actions (EAs) that operate on text blocks spanning multiple lines. Such EAs are common in developers' practice, such as moving a code block for conditional branching or duplicating a method definition block for overloading. Existing tools represent such block-level operations as discrete sequences of line-level EAs, compelling developers to manually correlate them and thereby substantially impeding the efficiency of change comprehension. To address this issue, we propose 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 mappings and block mappings. Leveraging the Kuhn-Munkres algorithm, we then compute the optimal mapping set that can minimize the size of the edit script (ES) while closely aligning with the original developer's intent. To validate the effectiveness of 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 evaluate 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 regarding result quality and their infeasibility in terms of runtime efficiency. We have implemented a web-based visual differencing tool.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑