Skip to content

perf(license): remove quadratic rescans on long repetitive attribution lists - #1452

Merged
mstykow merged 1 commit into
mainfrom
perf/license-seq-match-repetitive-lists
Oct 11, 2026
Merged

mstykow merged 1 commit into
mainfrom
perf/license-seq-match-repetitive-lists

Conversation

@mstykow

@mstykow mstykow commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Files that repeat a short licence tag on every line (one name.ogg Author / GPL V3+ per line, 300 KB-1 MB) took more than 300 s to scan. Three quadratic steps were responsible; each is now proportional to the work it has to do, with byte-identical output.
    • Sequence matching rescanned the whole remaining query for every single-token hit. The longest-match search now stops once nothing later can beat the best run, and visits only the query positions whose token occurs in the rule range.
    • merge_overlapping_matches removed merged matches with Vec::remove, shifting the tail each time. It now unlinks them in O(1), preserving the existing anchor-removal behaviour.
    • The low-coverage wrapper filter compared every sequence match with every exact match. It now looks only at exact matches near the wrapper.

Issues

How to verify

  • Take any of the attached slow-files and run provenant scan --license --compat-mode scancode --json-pp - <dir> on a build from this branch and from main. Output matches on every truncation I compared; the full files no longer time out.
  • Measured on a 408 KB prefix of one file, --license only: 28 s on main, 2.2 s here. The largest file (1.04 MB): 45 s after the first fix alone, 11.6 s now. All 44 files complete (--license --copyright, --processes 4, 117 s wall in total).

Follow-up work

  • Created or intentionally deferred: these inputs still produce about a million one-token sequence matches that are discarded later, so time grows faster than linearly on the largest files. Pruning them at the source would need a parity analysis, so it is not in this PR.

@greptile-apps

greptile-apps Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue remains.

Summary

This PR cuts repeated work when scanning long attribution lists:

  • Sequence searches skip positions that cannot match the current rule.
  • Match merging unlinks removed entries without shifting later matches.
  • Low-coverage wrappers check only nearby exact matches.

No new actionable issues were found. The previous test finding is fully addressed, and the profiling prints are gone.

Reviews (3) · Last reviewed commit: "perf(license): remove quadratic rescans ..." · Reviewed by Greptile

Comment thread src/license_detection/mod.rs Outdated
Comment thread src/license_detection/seq_match/matching.rs Outdated
@mstykow
mstykow force-pushed the perf/license-seq-match-repetitive-lists branch from e0ef2a3 to 548a1af Compare October 11, 2026 17:31
…n lists

Files that repeat a short licence tag on every line (e.g. one
"name.ogg  Author / GPL V3+" per line, 300 KB-1 MB) took more than 300 s
to scan. Three quadratic steps were responsible, each now linear in the
work it actually has to do, with byte-identical output:

- Sequence matching rescanned the whole remaining query for every
  single-token hit. The longest-match search now stops once nothing later
  can beat the best run, and visits only query positions whose token
  occurs in the rule range instead of every position.
- merge_overlapping_matches removed merged matches with Vec::remove,
  shifting the tail each time; it now unlinks them in O(1).
- The low-coverage wrapper filter compared every sequence match with
  every exact match; it now only looks at exact matches near the wrapper.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Maxim Stykow <maxim.stykow@gmail.com>
@mstykow
mstykow force-pushed the perf/license-seq-match-repetitive-lists branch from 548a1af to 42f0fbf Compare October 11, 2026 17:42
@mstykow
mstykow merged commit 3ece3ef into main Oct 11, 2026
13 checks passed
@mstykow
mstykow deleted the perf/license-seq-match-repetitive-lists branch October 11, 2026 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant