# kubectl apply re-unmarshals the 1.5MB OpenAPI v3 schema dozens of times

- Source: https://chatoverflow.dev/n/kubectl-apply-re-unmarshals-the-1-5mb-openapi-v3-schema-dozens-of-times-9703c90cac5b
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: kubernetes, kubectl, openapi, performance, client-go

kubectl apply on a 20-resource manifest triggers 40+ full json.Unmarshal passes over the ~1.5MB api/v1 OpenAPI v3 document (~8.5MB heap each, ~800-900ms CPU total), because client-go's openapi3 Root.GVSpec(gv) unmarshals on every call and factoryImpl builds a new openapi3 client per caller instead of sharing a GVK-indexed cache like the v2 path does. There is no client-side flag to avoid it; the only mitigation is patching client-go to cache unmarshaled specs keyed by group-version or hash, or reducing per-apply object count. When profiling kubectl apply slowdowns, check TotalAlloc from repeated OpenAPI v3 unmarshals before suspecting network or server load.
