Skip to content

perf: deduplicate matches with a set - #4910

Merged
kddejong merged 1 commit into
aws-cloudformation:mainfrom
hoganbr-amzn:perf/dedup-matches-set
Nov 3, 2026
Merged

kddejong merged 1 commit into
aws-cloudformation:mainfrom
hoganbr-amzn:perf/dedup-matches-set

Conversation

@hoganbr-amzn

Copy link
Copy Markdown
Contributor

Issue #, if available: none

Description of changes:

runner/template/runner.py::_dedup kept a list of matches seen so far and scanned it for every new match, so a template with N findings paid N^2 Match.__eq__ calls. Measured on a 2 MB template with 3,000 findings: 0.62 s in _dedup alone.

The list becomes a set of keys covering every field Match.__eq__ compares (message, rule.id, filename, line and column bounds, parent_id). Match itself is not hashable through its rule (rules compare by id but are not hashable), so the key is a tuple rather than the Match. Output order and first-occurrence semantics are unchanged; a test pins both.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

_dedup scanned a list of seen matches for every new match, so a template
with N findings paid N^2 Match.__eq__ calls: 0.6 s for 3,000 findings.
Keep a set of tuples covering every field Match.__eq__ compares instead.
The key is a tuple rather than the Match because rules compare by id but
are not hashable; Match.id is derived from the keyed fields.

Signed-off-by: Brenden Hogan <hoganbr@amazon.com>
@kddejong
kddejong force-pushed the perf/dedup-matches-set branch from ed37953 to 40a4b9c Compare November 3, 2026 22:47
@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.80%. Comparing base (dbb3da3) to head (40a4b9c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4910   +/-   ##
=======================================
  Coverage   94.80%   94.80%           
=======================================
  Files         441      441           
  Lines       16128    16129    +1     
  Branches     3130     3130           
=======================================
+ Hits        15290    15291    +1     
  Misses        463      463           
  Partials      375      375           
Flag Coverage Δ
unittests 94.79% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kddejong
kddejong merged commit 031fdc3 into aws-cloudformation:main Nov 3, 2026
24 checks passed
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.

2 participants