Abstract
Code clone detection is a critical task for software maintenance, yet existing tools often struggle to balance high-precision semantic detection with the scalability required for modern industrial codebases. Gitor introduces a novel framework that moves beyond isolated code analysis by constructing a Global Sample Graph (GSG). By representing the entire codebase as an interconnected network of features and utilizing high-performance node embeddings, Gitor achieves state-of-the-art recall for complex semantic clones while processing 100 million lines of code in just over an hour.
Introduction
Detecting code clones—fragments of code that are identical or similar—is vital for bug fixing, license compliance, and refactoring. Clones are typically categorized into four types, ranging from Type-1 (exact textual matches) to Type-4 (semantic clones with identical functionality but different implementations).
Traditional tools often rely on local features like token overlap or Abstract Syntax Trees (ASTs), which ignore the broader relationships across a database. Furthermore, tools capable of finding difficult Type-4 clones frequently suffer from poor scalability. Gitor bridges this gap by leveraging global context to identify latent similarities that local analysis misses.
The Gitor Pipeline
Gitor’s methodology is divided into three primary phases: Global Graph Construction, Node Embedding, and Clone Detection.
1. Global Graph Construction
Instead of analyzing samples in a vacuum, Gitor extracts individual information from every code sample in the database. This includes keywords (reserved language tokens) and side information (structural metadata such as nesting depth, loop counts, and flow-control density).
These features are used to build a massive, weighted directed graph. In this graph, nodes represent either code samples or specific features. An edge is created between a sample node and a feature node if the sample contains that feature, with the edge weight reflecting the feature's frequency. This structure allows features to act as "bridges" between disparate code samples.
2. Node Embedding
To process this massive graph efficiently, Gitor employs ProNE, a fast and scalable network embedding algorithm. ProNE transforms each code sample node into a low-dimensional vector. Because these vectors are derived from the global graph, they capture the latent relationships between samples that share structural patterns, even if their literal text differs significantly.
3. Clone Detection
Once the vectors are generated, clone detection is reduced to a high-speed similarity search. Gitor calculates the cosine similarity between vectors; if the similarity score exceeds a predefined threshold, the pair is flagged as a clone. Additionally, Gitor can act as a "booster" for other tools, where its global vectors are concatenated with local vectors from models like Word2vec or Code2vec to improve overall accuracy.
Experimental Results
The authors evaluated Gitor using BigCloneBench (for accuracy) and the IJaDataset (for scalability).
- Superior Recall: On BigCloneBench, Gitor outperformed state-of-the-art tools like SourcererCC and Oreo. It was particularly effective for "Moderately Type-3" clones, achieving a recall of 0.601, which doubled the performance of the next best tool.
- Massive Scalability: Gitor analyzed 100 million lines of code (LOC) in approximately 1 hour and 7 minutes. In contrast, the token-based tool CCFinder required nearly 10 hours for the same task, while many semantic detectors failed to complete the process entirely.
- Precision: Despite its speed, Gitor maintained a high precision of 0.951, ensuring that the results are reliable for developers.
Conclusion
Gitor demonstrates that global context is a powerful and underutilized signal in code clone detection. By representing a codebase as a unified graph of features and samples, Gitor achieves a unique balance: the deep semantic insight typically reserved for heavy-weight program analysis and the extreme scalability of simple lexical tools. Future work will focus on optimizing the final pair-wise comparison step to further enhance performance on billion-line datasets.
Summary updated