Repository navigation
perf(conditions): solve each set of condition pins once - #4992
Merged
kddejong merged 1 commit intoNov 5, 2026
Merged
Conversation
Conditions.evolve and Conditions.is_reachable copied the template's condition CNF and ran a satisfiability check on every call. A template where many resources use the same conditions in Fn::If asks the same few questions thousands of times. A Conditions now stores its pins (every pinned condition) and its hard pins (the pins that are facts rather than scenario assumptions) instead of two CNF copies. Satisfiability is cached per set of pins, which fully decides it, in a dict shared by every Conditions evolved from the same template. cnf and hard_cnf become read-only properties that build a new CNF from the template clauses plus one clause per pin. Fixes aws-cloudformation#4991
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4992 +/- ##
=======================================
Coverage 94.80% 94.81%
=======================================
Files 441 441
Lines 16165 16179 +14
Branches 3135 3137 +2
=======================================
+ Hits 15326 15340 +14
Misses 463 463
Partials 376 376
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
kddejong
approved these changes
Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available: Fixes #4991
Description of changes:
Conditions.evolveandConditions.is_reachablecopied the template's condition CNF and ran a satisfiability check on every call. A template where many resources use the same conditions inFn::Ifasks the same few questions thousands of times: the reproduction in #4991 makes 6,390 checks for 114 distinct sets of pinned conditions.A
Conditionsnow stores its pins (every pinned condition) and its hard pins (the pins that are facts rather than scenario assumptions) instead of two CNF copies. Satisfiability is cached per set of pins, which fully decides it, in a dict shared by everyConditionsevolved from the same template.cnfandhard_cnfbecome read-only properties that build a new CNF from the template clauses plus one clause per pin; nothing insrc/reads them, and the constructor no longer takes them. This also stopscnffrom collecting a duplicate clause for each carried-over pin on everyevolve.Reproduction from #4991 (
cfn-lint --regions us-east-1 -- repro.yaml, aftercfn-lint --update-specs):mainPeak RSS is unchanged (about 135-140 MB on both).
The remaining 2,400 solver calls on the reproduction come from
build_scenariosinsrc/cfnlint/conditions/conditions.py, which this PR does not change.pytest test(3,449 passed) andpre-commit run --all-filespass. The 258 templates undertest/fixtures/templateslint to the same matches asmain, apart from the order of resource names inside E3019 messages, which already varies withPYTHONHASHSEEDonmain. The new tests cover repeated, reordered, reachability and unsatisfiable questions, facts versus assumptions with equal statuses, and the one-clause-per-pin CNF. An end-to-end test lints 5 and then 20 conditional alarms that reuse the same conditions inFn::Ifand asserts the solver call count does not change: 9 at both sizes here, 65 and 260 onmain.#4756 (open) also changes
_conditions.py. Itsevolve_for_regionsadds a region clause tocnfbut nothard_cnf, so that W1028 does not treat region-specific branches as unreachable. With this PR the clause cannot simply join_base_cnf, which sits under the hard pins too. It would need its own base forcnfonly, and a separate cache for it, whichever PR lands first.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.