fieldpath: preallocate capacity in PathElementSet and SetNodeMap set operations #352
All Vouch review confidence checks passed
Residual risk 0.33 = Change Risk (0.59) × (1 − Review Confidence (0.45)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.59 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #352"
general
weight: 0.35
mauriciopoppe
What type of PR is this?
/kind cleanup
What this PR does / why we need it
In
fieldpath.PathElementSetandfieldpath.SetNodeMap, set operations (Union,Intersection,Difference, andRecursiveDifference) previously initialized result slices with zero capacity. As matching or differing elements were encountered, repeatedappendoperations caused multiple internal slice reallocations and memory copies.This PR preallocates output slice capacity up front when sizes are known or bounded, and short-circuits empty set cases cleanly without extra allocations while preserving nil slice semantics for empty sets (ensuring full compatibility with
reflect.DeepEqualtests).For
Union, output slices are preallocated tomax(len(s.members), len(s2.members))rather thanlen(s.members) + len(s2.members)to avoid 2x overallocation and retained excess capacity when sets are identical or subsets (common across Server-Side Apply reconciliations and shared non-leaf schema paths).Which issue(s) this PR fixes
Fixes #
Special notes for your reviewer
Authentic benchmark comparison on
linux/amd64usingbenchstatwithn=10iterations.Reproduction command:
Benchstat summary (n=10)
Integration Benchmark (BenchmarkRequestCost in kubernetes/kubernetes, n=6)
To verify real-world server impact and ensure no regressions across Kubernetes API server operations, structured-merge-diff PR #352 (commit
450d1cd87be6f72d7da0bc0c4c04e09c27b0b46b) was vendored intokubernetes/kubernetes(base master commit704449b06d6551d0b95c9f0257f225ef63636f6e) and evaluated using the upstream integration benchmark suitetest/integration/apiserver/flowcontrol/cost/cost_test.go.The test ran on a dedicated
c3-standard-44GKE node (Intel(R) Xeon(R) Platinum 8481C CPU @ 2.70GHz, Guaranteed QoS pod, static CPU pinningCpus_allowed_list: 1-2,23-24,GOMAXPROCS=4,n=6iterations).Reproduction command:
Benchstat summary: sec/op, B/op, allocs/op (n=6)
The complete 11-metric benchstat comparison and verbatim 72-run benchmark outputs (
before.txtandafter.txt) are documented in the PR comments:Does this PR introduce a user-facing change?
``
release-note
``NONE