Skip to content

perf(iac): avoid redundant parsing in file type detection#10941

Open
HairyMike wants to merge 1 commit into
aquasecurity:mainfrom
HairyMike:perf/iac-detection-parse-once
Open

perf(iac): avoid redundant parsing in file type detection#10941
HairyMike wants to merge 1 commit into
aquasecurity:mainfrom
HairyMike:perf/iac-detection-parse-once

Conversation

@HairyMike

@HairyMike HairyMike commented Jul 9, 2026

Copy link
Copy Markdown

Description

  • Kubernetes, CloudFormation, and Terraform Plan JSON matchers previously called IsType recursively, fully parsing each candidate file multiple times during misconfiguration filtering.
  • Each matcher now reads file content once and unmarshals once.

On repositories with many YAML/JSON files that are not IaC (e.g. OpenAPI specs), the detection phase alone can allocate multiple GB before any policy evaluation runs. This removes the worst redundant parses without changing the public API.

Before / after

Apple M3 Pro, GOEXPERIMENT=jsonv2, go test ./pkg/iac/detection/ -bench=BenchmarkIsType -benchmem -count=10

Benchmark Before After
IsType_Kubernetes_YAML_1x 27.1 µs/op, 371 allocs/op 12.4 µs/op, 186 allocs/op (−54%)
IsType_CloudFormation_YAML_1x 22.7 µs/op, 321 allocs/op 10.7 µs/op, 138 allocs/op (−53%)
Per-file detection during misconfiguration filtering now parses each candidate YAML once instead of 2–3 times.

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@HairyMike
HairyMike requested a review from nikpivkin as a code owner July 9, 2026 11:28
@CLAassistant

CLAassistant commented Jul 9, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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