Files
codebase-memory-mcp/tests/fixtures/complexity/Go/controller.go
T
Martin Vogel 1eb55031e6 perf(k8s): infra resolvers stay linear in the repository's copies
The complexity guard (O(n^2) detection) had no infrastructure corpus, and
the infra resolvers looked candidates up by name across the whole
repository and then filtered them: an object reference by "Kind/name", a
selector by its rarest label pair, a custom resource by its CRD's
group/kind, a controller's kind by the Go type's name. Independent copies
share every name, so with k copies each lookup visited all k: the work
grew ~4x per doubling while the edges stayed ~2x.

Candidates are now looked up where they can match:
- K8s references, selectors and CRDs through indexes keyed by the bundle
  (kustomize build root / chart / dir, and the deploy scopes for
  references) and the name, type or label pair; a source visits only the
  bundles it is in. The repository-wide fallback for a custom resource
  without a CRD beside it stays (it stands for every copy by design);
- the operator pass through a (package dir, type) index: a controller's
  kind is one lookup in the imported or own package; only an import no
  module of the repository has still checks the same-named types. Group
  declarations are deduplicated through a set, not a scan.

Child access in the K8s extractor goes through a tree cursor:
ts_node_named_child(n, i) walks from the first child on every call, so the
index loops over mapping pairs, sequence items and a file's documents were
quadratic in a wide node.

The guard gains fixtures (tests/fixtures/complexity/Kubernetes: a
kustomize bundle with workloads, Service, Ingress, PDB, NetworkPolicy,
HPA, RBAC, CRD + CR, cert-manager; tests/fixtures/complexity/Go: a
controller-runtime operator with +groupName types and an embedded CRD),
work counters g_k8s_candidates / g_op_candidates, and a gate on them and
on the fixtures' own node and edge growth; fixture dirs now also apply to
templated languages. An API group is one identity across a repository, so
the fixtures' CRDs use groups no copy's Go code declares -- the guard
measures accidental growth, not that by-design join. The originality
check covers the infra sources and scans them against yaml-language-server,
helm-ls, kustomize, Flux's kustomize package and controller-tools.

Before: k8s candidates 126 -> 504 (4.00x), operator 45 -> 288 (6.40x)
per doubling; after: 42 -> 84 and 6 -> 12 (2.00x), fixture edges 2.01x.
On 17 infrastructure repositories the graphs are identical to before;
three runs build identical graphs. Index wall time against origin/main,
median of three: deckhouse 9.58 -> 9.59 s, kubermatic 2.93 -> 2.93 s,
cloud-foundation-fabric 1.90 -> 1.90 s. A manifest of thousands of
documents indexes ~10 % faster (2.40 -> 2.13 s).

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-11 00:24:41 +02:00

15 lines
260 B
Go

package op
import (
ctrl "sigs.k8s.io/controller-runtime"
)
type WidgetReconciler struct{}
func (r *WidgetReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&Widget{}).
Owns(&Gadget{}).
Complete(r)
}