Skip to content

perf(dao): count node pods once per refresh - #4370

Merged
uozalp merged 1 commit into
derailed:masterfrom
b84330808:node-list-pod-count
Nov 10, 2026
Merged

uozalp merged 1 commit into
derailed:masterfrom
b84330808:node-list-pod-count

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

Fixes #4367

Node.List called CountPods for each node, and each call walked every pod, so a refresh cost nodes × pods. Node.Get converted every pod to a typed v1.Pod only to count the ones on that node.

Both now walk the pods once into a map of counts per node. CountPods and GetPods had no other callers, so they're removed.

The benchmarks are in node_test.go (30 pods per node, GOMAXPROCS=2, i7-9700, Windows 11, median of 3 runs of -benchtime=5x):

before after
List, 50 nodes 2.05 ms 0.075 ms
List, 200 nodes 33.7 ms 0.39 ms
List, 1,000 nodes 1.95 s 3.0 ms
Get, 200 nodes 28.4 ms, 8.2 MB 0.38 ms, 13.5 KB

TestNodeListPodCount and TestNodeGetPodCount check the counts. golangci-lint v2.13 finds nothing.

Node.List walked all the pods once per node on every refresh, which is
O(nodes*pods), and Node.Get converted every pod to a typed v1.Pod only to take
the length of the matching ones.

Walk the pods once, into a map of counts per node, for both. CountPods and
GetPods have no other callers, so they go away.

@uozalp uozalp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@uozalp
uozalp merged commit f1673d3 into derailed:master Nov 10, 2026
3 checks passed
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.

Node view walks every pod once per node on each refresh

2 participants