一句话:提出基于 HyperAST 的增量、内存友好代码差异计算,使 GumTree 式 diff 可扩展到大型代码历史。
面向时间的代码分析(如缺陷归因、缺陷预测与代码演化分析)需要计算大量版本间的代码差异,但逐版本解析 AST 并重复计算差异造成严重可扩展性瓶颈。本文提出 HyperDiff,利用表示代码历史的 HyperAST 这一面向时间的数据结构,将主流 GumTree 差异算法惰性化,从而实现增量且内存高效的差异计算。作者在 19 个大型软件项目上与 GumTree 对比评估。结果表明,该方法在时间与内存上均优于 GumTree:总 diff 计算 CPU 时间加速 1.2 至 12.7 倍,中间阶段最高加速 226 倍,每 AST 节点的内存占用相差 4.5 倍,且与 GumTree 产生 99.3% 相同的 diff。
With the advent of fast software evolution and multistage releases, temporal code analysis is becoming useful for various purposes, such as bug cause identification, bug prediction or code evolution analysis. Temporal code analyses can consist in analyzing multiple Abstract Syntax Trees (ASTs) extracted from code evolutions, e.g. one AST for each commit or release. Core feature to temporal analysis is code differencing: the computation of the so-called Diff or edit script between two given versions of the code. However, jointly analyzing and computing the difference on thousands versions of code faces scalability issues. Mainly because of the cost of: 1) parsing the original and evolved code in two source and target ASTs; 2) wasting resources by not reusing intermediate computation results that can be shared between versions. This paper details a novel approach based on time-oriented data structures that makes code differencing scale up to large software codebases. In particular, we leverage on the HyperAST, a novel representation of code histories, to propose an incremental and memory efficient approach by lazifying the well known GumTree diffing algorithms, a mainstream code differencing algorithm and tool. We evaluated our approach on a curated list of 19 large software projects and compared it to GumTree. Our approach outperforms it in scalability both in time and memory. We observed an order-of-magnitude difference: 1) in CPU time from x1.2 to x12.7 for the total time of diff computation and up to x226 in intermediate phases of the diff computation, and 2) in memory footprint of x4.5 per AST node. The approach produced 99.3% of identical diffs with respect to GumTree.