Files
coder/provisioner
George K a3876a3634 perf(provisioner/terraform): optimize selectors and tune graph limits (#31177)
Resolving a selector for a specific script instance previously scanned
every instance of that resource, making long chains of instances of
the same resource quadratic.

Index normalized count/string instance keys once and resolve indexed
selectors directly, preserving key semantics and deferred address
errors.

Benchmarked on one pinned CPU; CPU time and allocation results are as
follows:

- A 5,000-rule chain's Plan conversion fell from 11.08 s to 133 ms,
  with cumulative heap allocation falling from 4.14 GB/op to 138
  MB/op. State conversion fell from 11.12 s to 167 ms.

- A 100,000-edge Cartesian State conversion changed from 72.9 ms to
  73.7 ms, adding 96 KB/op. This small indexing cost is justified by
  the chain improvement.

Retain the 100,000 candidate dependency cap: direct graph construction
handled a 100,000-edge chain in 262 ms with 195 MiB peak RSS.

Tighten `tfgraph` parsing to 16 MiB DOT, 25,000 nodes, 100,000 edges,
125,000 statements, and 4 MiB each for cumulative node IDs and
retained addresses. Old-limit fixtures reached 950 MiB RSS; some
benchmark processes exceeded the harness’s 1 GiB RSS cutoff and were
stopped. The largest tested fixture combining the new node/edge limits
peaked at 189 MiB.

Reduce reference lookups from 1,000,000 to 100,000 per Query. In the
repeated module-output lookup benchmark, the former consumed 3.43 s
CPU and allocated 5.76 GB, versus 343 ms and 576 MB at the selected
budget. Retain the million-visit/edge traversal budgets.

`tfgraph` currently has no production callers. Revalidate these parser
and query limits when plan-time agent runtime resolution is
integrated.

Refs: https://linear.app/codercom/issue/CORE-554
2026-10-23 09:41:39 -07:00
..