Skip to content

fix(terraform): improve performance in nested modules by reducing allocations#7519

Open
patrickvinograd wants to merge 4 commits intobridgecrewio:mainfrom
patrickvinograd:nested-loop-performance-fix
Open

fix(terraform): improve performance in nested modules by reducing allocations#7519
patrickvinograd wants to merge 4 commits intobridgecrewio:mainfrom
patrickvinograd:nested-loop-performance-fix

Conversation

@patrickvinograd
Copy link
Copy Markdown

@patrickvinograd patrickvinograd commented Apr 17, 2026

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Description

Improves the performance of terraform scans in states with deeply nested modules:

  • Moves the allocation of a static list of source types out of the inner loop of S3AllowsAnyPrincipal.py
  • Uses a list instead of an array in the vertex-walking code in module_handler.py to avoid that list growing very large, also within an inner loop.

Motivation: We have several terraform projects that are highly modularized with deeply nested modules. We observed step performance regressions in 3.2.34 and 3.2.119 and after my teammate did some local profiling, have been patching checkov locally with these fixes, but would like to upstream them. With these fixes we see a 6-7x performance improvement when scanning such terraform projects.

I did not see any obvious performance tests that I could add to but functionally these changes seem equivalent to existing behavior and low-risk given existing test coverage.

Fixes: #7524

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature, policy, or fix is effective and works
  • New and existing tests pass locally with my changes

@maxamel
Copy link
Copy Markdown
Contributor

maxamel commented Apr 30, 2026

Thanks @patrickvinograd , can you check the failing workflows please?

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.

Performance regressions for deeply-nested terraform modules

2 participants