NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Clone Detection on Large Scala Codebases

Wahidur Rahman, Yisen Xu, Fan Pu, Jifeng Xuan, Xiangyang Jia, Michail Basios, Leslie Kanthan, Lingbo Li, Fan Wu, Baowen Xu

TL;DR

Researchers evaluated state-of-the-art clone detection tools on a massive 4-million-line industrial Scala codebase, finding that performance differs drastically from open-source benchmarks. While tools like SourcererCC and AutoenCODE excel on GitHub projects, their precision drops by up to 30% in industrial settings because professional developers define "clones" based on refactorability rather than just syntax.

What Problem Does This Paper Address?

Code cloning—the practice of copying and pasting code segments—is a double-edged sword. It speeds up development but creates a maintenance nightmare when bugs propagate through identical snippets. While the research community has developed sophisticated tools to detect these clones, most have been tuned and tested on open-source software (OSS).

The authors identify a significant "open-source bias." Industrial environments are often "closed gardens" where developers are forbidden from downloading external code. This paper asks: Do the clone patterns we see on GitHub actually exist in private corporate repositories? And do the tools we’ve built actually work for professional engineers?

Methods

The study compares two "state-of-the-art" approaches adapted for the Scala language:

  1. SourcererCC: A token-based algorithm that represents code as a "bag of tokens." It’s highly scalable and uses optimized indexing to find overlaps quickly.
  2. AutoenCODE: A deep-learning approach that uses Recursive Autoencoders to create "sentence embeddings" of code fragments. It looks at multiple representations, including Identifiers and Abstract Syntax Trees (AST).

The researchers didn't just run the tools; they established a "ground truth" by having 67 professional developers from the partner company manually label 201 method pairs, while the authors labeled 1,000 pairs from open-source projects.

Datasets

The study utilized two distinct datasets:

  • Open Source: The top 20 most popular Scala projects on GitHub (e.g., scala-2.13.x, playframework, sbt), totaling roughly 1.6 million lines of code (LoC).
  • Industrial: A private codebase from an anonymous company containing over 4 million LoC and maintained by hundreds of developers. This environment strictly prohibited external code reuse.

Key Insights and Ideas

  • The "Refactorability" Filter: The most striking insight is that industrial developers have a different definition of a "clone." In academia, a clone is defined by syntactic similarity. In industry, developers often refused to label similar segments as clones if they were unrefactorable. If you can't merge the code into a single function, they don't consider it a clone worth flagging.
  • The Type-3 Disparity: Clone detection usually categorizes clones from Type-1 (identical) to Type-4 (semantically similar but syntactically different). The study found that Type-3 clones (near-miss clones with added/deleted statements) are far less common in industry (13.9%) than in OSS (64.1%).
  • Closed vs. Open Environments: Because industrial devs can't "forage" for code on StackOverflow or GitHub, the "fuzzy" copying that leads to Type-3 clones happens less frequently. Most industrial clones are either very obvious (Type-1/2) or purely coincidental.

Key Results

  • Precision Drop: On open-source projects, both tools were highly precise (up to 99.6%). However, on the industrial codebase, precision plummeted. SourcererCC dropped to 77.8%, and AutoenCODE (AST) fell to 64.4%.
  • Recall Boost: Interestingly, recall improved in the industrial setting (increasing by up to 32.4%). This suggests the tools are "over-detecting"—finding many similarities that the tools think are clones, but the developers do not.
  • Scalability: SourcererCC remains the speed king, processing the 4M LoC codebase in seconds/minutes, while the deep-learning-based AutoenCODE took orders of magnitude longer (up to several hours).

Limitations and Future Work

The authors acknowledge that their industrial data comes from a single organization. While it is a massive codebase, the culture of that specific company might influence the results.

Future work suggests that clone detection tools need to move beyond simple syntax matching. To be truly useful in an industrial pipeline, these tools need to incorporate "refactorability analysis"—essentially predicting whether a developer would actually want to act on the detected clone. The authors also suggest investigating how functional programming features in Scala (like pattern matching) uniquely influence clone patterns compared to traditional imperative languages.

Summary updated

BibTeX
@inproceedings{rahman2020clone,
  author = {Wahidur Rahman and Yisen Xu and Fan Pu and Jifeng Xuan and Xiangyang Jia and Michail Basios and Leslie Kanthan and Lingbo Li and Fan Wu and Baowen Xu},
  title = {{Clone Detection on Large Scala Codebases}},
  booktitle = {IWSC},
  year = {2020},
  url = {https://openreview.net/forum?id=TJNYhPbjbi},
}
Figure