TitleNearest-neighbor, BERT-based, scalable clone detection: A practical approach for large-scale industrial code bases
Publication TypeJournal Article
Year of Publication2024
AuthorsAhmed GAftab, Patten JVincent, Han Y, Lu G, Hou W, Gregg D, Buckley J, Chochlov M
JournalSoftware: Practice and Experience
Volumen/a
Keywordsclone detection, Deep Neural Networks, scalable, semantic clones
Abstract

Abstract Hidden code clones negatively impact software maintenance, but manually detecting them in large codebases is impractical. Additionally, automated approaches find detection of syntactically-divergent clones very challenging. While recent deep neural networks (for example BERT-based artificial neural networks) seem more effective in detecting such clones, their pairwise comparison of every code pair in the target system(s) is inefficient and scales poorly on large codebases. We present SSCD, a BERT-based clone detection approach that targets high recall of Type 3 and Type 4 clones at a very large scale (in line with our industrial partner's requirements). It computes a representative embedding for each code fragment and finds similar fragments using a nearest neighbor search. Thus, SSCD avoids the pairwise-comparison bottleneck of other neural network approaches, while also using a parallel, GPU-accelerated search to tackle scalability. This article describes the approach, proposing and evaluating several refinements to improve Type 3/4 clone detection at scale. It provides a substantial empirical evaluation of the technique, including a speed/efficacy comparison of the approach against SourcererCC and Oreo, the only other neural-network approach currently capable of scaling to hundreds of millions of LOC. It also includes a large in-situ evaluation on our industrial collaborator's code base that assesses the original technique, the impact of the proposed refinements and illustrates the impact of incremental, active learning on its efficacy. We find that SSCD is significantly faster and more accurate than SourcererCC and Oreo. SAGA, a GPU-accelerated traditional clone detection approach, is a little better than SSCD for T1/T2 clones, but substantially worse for T3/T4 clones. Thus, SSCD is both scalable to industrial code sizes, and comparatively more accurate than existing approaches for difficult T3/T4 clone searching. In-situ evaluation on company datasets shows that SSCD outperforms the baseline approach (CCFinderX) for T3/T4 clones. Whitespace removal and active learning further improve SSCD effectiveness.

URLhttps://onlinelibrary.wiley.com/doi/abs/10.1002/spe.3355
DOI10.1002/spe.3355