BDiff: Block-aware and Accurate Text-based Code Differencing DOI: XXXXXXX.XXXXXXX Conference: Make sure to enter the correct conference title from your rights confirmation email; June 03–05, 2018; Woodstock, NY ISBN: 978-1-4503-XXXX-X/2018/06 CCS: Software and its engineering Software configuration
Yao Lu, Wanwei Liu, Tanghaoran Zhang, Kang Yang, Yang Zhang, Wenyu Xu, Longfei Sun, Xinjun Mao, Shuzheng Gao, Michael R. Lyu · 2025
Read BDiff: Block-aware and Accurate Text-based Code Differencing DOI: XXXXXXX.XXXXXXX Conference: Make sure to enter the correct conference title from your rights confirmation email; June 03–05, 2018; Woodstock, NY ISBN: 978-1-4503-XXXX-X/2018/06 CCS: Software and its engineering Software configuration by Yao Lu, Wanwei Liu, Tanghaoran Zhang, Kang Yang, Yang Zhang, Wenyu Xu, Longfei Sun, Xinjun Mao, Shuzheng Gao, Michael R. Lyu (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2510-21094.txt.
Introduction
Yao Lu leads nine co-authors on BDiff, a text based code differencing tool that recognizes edits acting on whole blocks of lines, such as moving a branch or duplicating a method. Differencing is basic software practice, yet line level tools shred block moves into long lists of small edits.
Developers then correlate those fragments by hand, wasting review time and inviting missed changes. Block aware differencing reports the operation at the level programmers actually think in. Accurate block level diffs improve code review, auditing, and research on how software evolves across versions.
Catalog record
| CREATOR | Yao Lu, Wanwei Liu, Tanghaoran Zhang, Kang Yang, Yang Zhang, Wenyu Xu, Longfei Sun, Xinjun Mao, Shuzheng Gao, Michael R. Lyu |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 72 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2510-21094
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
BDiff: Block-aware and Accurate Text-based Code Differencing DOI: XXXXXXX.XXXXXXX Conference: Make sure to enter the correct conference title from your rights confirmation email; June 03–05, 2018; Woodstock, NY ISBN: 978-1-4503-XXXX-X/2018/06 CCS: Software and its engineering Software configuration management and version control systems CCS: Software and its engineering Software maintenance tools CCS: Software and its engineering Maintaining software Yao Lu, Wanwei Liu, Tanghaoran Zhang, Kang Yang, Yang Zhang, Wenyu Xu, Longfei Sun, Xinjun Mao, Shuzheng Gao, Michael R. Lyu Abstract . Code differencing is a fundamental technique in software engineering practice and research. The most widely used differencing technology today remains text-based differencing methods, which operate at the textual line level. 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 ( EA s) that operate on text blocks spanning multiple lines. Such EA s 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 EA s, 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 EA s and five types of line-level EA s. 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. Based on the proposed algorithm, we have implemented a web-based visual differencing tool, which can be integrated into Git. We have open-sourced our tool at https://github.com/bdiff/bdiff . 1. Introduction Code differencing, a technique that computes the differences between two program versions, is fundamental and essential for both software engineering (SE) practice and research. Developers use code differencing tools to review code changes, debug defects, and track code evolution. Computer-aided software engineering tools rely on code differencing techniques as foundational support for tasks such as code merging. Furthermore, researchers employ these techniques in studies aimed at identifying bug introductions ( Da Costa et al. 2016 ; Hata et al. 2012 ; Quach et al. 2021 ) , mining change patterns ( Martinez and Monperrus 2019 ; Zhang et al. 2024 ) , measuring developer contributions ( Gousios et al. 2008 ; Lu et al. 2018 ) , etc. Existing code-differencing algorithms can be classified into two categories based on the representation of code ( Kim and Notkin 2009 ) : (1) text-based algorithms working on textual lines and (2) tree-based algorithms working on an abstract syntax tree (AST). Text-based methods, such as the traditional Myers algorithm ( Myers 1986 ) , compare raw source code at the character or line level. They typically use techniques like the longest common subsequence (LCS) to detect basic changes of lines and can be applied to any text file. In contrast, tree-based methods, such as ChangeDistiller ( Fluri et al. 2007 ) and GumTree ( Falleri et al. 2014 ) , parse code into ASTs and compare these ASTs to detect differences. These approaches capture structural and semantic changes more accurately, offering more fine-grained changes. A major limitation of these methods is that they are language-dependent and require adapting different parsers for various programming languages and language versions. Currently, owing to their universality, efficiency, and robustness, developers generally use text-based differencing tools in practice ( Fluri et al. 2025 ; Nugroho et al. 2019 ) , and we focus on this technical approach. Figure 1. A real case of line updating, block moving, and block copying (psf/black, e1e8909, black.py) Text-based differencing has been a long-standing research topic, and a suite of notable algorithms has been proposed and refined over time. The Hunt-McIlroy algorithm ( Hunt and McIlroy 1976 ) , proposed in 1976, serves as a foundational method for computing the LCS between two sequences. The Myers algorithm ( Myers 1986 ) , adopting a greedy strategy, is a highly efficient and influential method for computing the minimum edit script ( ES ) between two sequences, i.e. , the minimum number of edit actions ( EA s) required to transform one sequence into the other. A limitation of these traditional algorithms is that the computed EA s are only represented as deletions and insertions. These primitive EA s often fail to capture developers’ actual changes such as line updates. To address this limitation, Canfora et al. ( Canfora et al. 2009a ; Canfora et al. 2009b ) proposed ldiff, a method that takes the output of the Myers algorithm as input and can identify line updates and line moves. Furthermore, other related works ( Godfrey and Zou 2005 ; Duala-Ekoko and Robillard 2007 ; Reiss Steven 2008 ; Asaduzzaman et al. 2013 ) have developed algorithms capable of tracking the evolution of source code lines, e.g., line splitting and line merging in LHDiff ( Asaduzzaman et al. 2013 ) . While existing works have made progress in identifying line-level changes, they exhibit a key limitation in detecting block-level changes, which poses substantial challenges for developers in effectively understanding actual change intentions. In practice, developers frequently perform edit operations on multi-line code blocks, e.g., moving a code block into an if -condition structure for defensive programming, or duplicating a function block with subsequent modifications to implement function overloading ( Ahmed et al. 2015 ) . Figure 1 presents the Git diff view of a historical commit from the GitHub project “ psf/black ”. The differencing results consist of 4 consecutive deleted lines and 13 consecutive added lines. Through a detailed analysis, however, we can infer that the developer actually moved a code block (spanning lines 991–993) into an if -condition and copied the same block into an elif -condition. This example illustrates that a single block-level EA corresponds to multiple line-level EA s. Identifying such block-level EA s can therefore substantially reduce the ES size and help developers more efficiently comprehend edit intent. Moreover, in real-world development scenarios, the two blocks involved in block-level EA s may be far apart, encompassing both changed code (for block movement) and unchanged code (for block duplication) from the original version, and the identified block-level EA s can therefore assist developers in evaluating the impact of code changes. However, identifying both line-level and block-level EA s that can minimize the size of the ES and are close to the original developer’s intent is challenging. Code files often contain multiple instances of identical or highly similar lines and blocks-this ambiguity can lead to scenarios