Repository navigation
🚀 Release v9.2.0: Algorithmic Overhaul & Unprecedented Precision
This release brings a massive architectural overhaul to the core scanning engines of phpcpd, introducing true O(1) hashing algorithms, early-exit strategies, and character-level tokenization. The result is a profoundly faster, mathematically accurate detection engine capable of handling Enterprise-scale codebases with flat scaling.
⚡ Performance Breakthroughs
-
O(1) Rolling Hash (Rabin-Karp): Completely rewrote the default Rabin-Karp hashing engine. We replaced the memory-heavy md5(substr()) operations with a true Double Polynomial Rolling Hash. This eliminates expensive string allocations in memory.
-
Suffix Tree "Fast Path" (O(N²) to O(N)): Historically, the Suffix Tree allocated heavy Levenshtein distance matrices even for exact matches. We introduced a "Fast Path" early-exit strategy that bypasses the dynamic programming matrix in favor of direct token-by-token comparison when --edit-distance=0.
-
Early Scanning Cutoff: The Suffix Tree traversal is now strictly constrained by the --min-tokens limit. If the remaining unparsed tokens are fewer than the required minimum, the engine immediately halts that branch, eliminating impossible tail evaluations.
🎯 Precision Enhancements & Bug Fixes
-
Character-Level Precision (Fix & Enhancement): Previously, both engines ignored single-character tokens returned as strings by token_get_all() (such as +, *, =, {). This caused false-positive clones between methods with identical structures but different math/logic, and completely missed valid architectural clones. Both DefaultStrategy and SuffixTreeStrategy now capture these primitives via their ASCII values (ord()), ensuring flawless structural comparison.
-
Fixed Suffix Tree Map Overwrite (Bug Fix): Fixed a critical deduplication bug where clones starting on the exact same line number in different files would silently overwrite each other. The internal map now securely uses a composite key ($ci->token->file . ':' . $ci->token->line), preventing false-negative clone drops during massive directory scans.
📊 Real-World Benchmarks
-
Rabin-Karp Scale Test (138,272 LOC): The new Rolling Hash delivers a 12% baseline speedup (2.33s vs 2.65s) on default settings, and cuts execution time by 45% (1.93s vs 3.53s) when detecting massive clones (--min-tokens=1000).
-
Suffix Tree Optimizations: The new Fast Path and Early Cutoff deliver a 90%+ speedup for exact matches (dropping execution from ~22s to fractions of a second on highly dense files) and a 35-40% time reduction for Type-3 fuzzy detection.
-
Suffix Tree Scale Test (9,200 LOC): The upgraded engine uncovers hidden clones missed in v9.1.0, parsing the volume in ~17 seconds for mathematically exact matches, and ~45 seconds when running deep Type-3 fuzzy analysis (--edit-distance=5).