Commit 847d836
Optimize O(n²) deduplication to O(n × m)
Both dedupe_more_specific() and dedupe_more_specific_hits() had nested
loops comparing every hit against every other hit, which is O(n²).
The key insight is that deduplication only matters for hits on the
same line. By grouping hits by line first (O(n)), we only compare
within each group. This reduces complexity to O(n × m) where m is
the average hits per line (typically 1-3).
Changes:
- Add early return for 0-1 hits
- Group hits by line using HashMap before comparison
- Skip single-hit lines entirely
- Only iterate within same-line groups
This prevents worst-case blowup on crypto-dense files (e.g., 100
findings would have been 10,000 comparisons, now ~100-300).
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>1 parent 083862b commit 847d836
1 file changed
Lines changed: 57 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
343 | 353 | | |
344 | | - | |
345 | | - | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
346 | 358 | | |
347 | 359 | | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
| 360 | + | |
| 361 | + | |
353 | 362 | | |
354 | 363 | | |
355 | 364 | | |
356 | 365 | | |
357 | 366 | | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
367 | 381 | | |
368 | 382 | | |
369 | 383 | | |
| |||
656 | 670 | | |
657 | 671 | | |
658 | 672 | | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
659 | 683 | | |
660 | | - | |
661 | | - | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
662 | 688 | | |
663 | 689 | | |
664 | | - | |
665 | | - | |
| 690 | + | |
| 691 | + | |
666 | 692 | | |
667 | 693 | | |
668 | | - | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | | - | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
677 | 705 | | |
678 | 706 | | |
679 | 707 | | |
| |||
0 commit comments