Skip to content

Commit

Permalink
perf: use empty struct to reduce memory usage (#2327)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Feb 11, 2023
1 parent b2eaea0 commit 0bd7c7e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/pod.go
Expand Up @@ -65,7 +65,7 @@ func (n *NamedPort) AddNamedPortByPod(pod *v1.Pod) {
if _, ok := n.namedPortMap[ns]; ok {
if _, ok := n.namedPortMap[ns][port.Name]; ok {
if n.namedPortMap[ns][port.Name].PortId == port.ContainerPort {
n.namedPortMap[ns][port.Name].Pods[podName] = ""
n.namedPortMap[ns][port.Name].Pods[podName] = struct{}{}
} else {
klog.Errorf("named port %s has already be defined with portID %d",
port.Name, n.namedPortMap[ns][port.Name].PortId)
Expand All @@ -77,7 +77,7 @@ func (n *NamedPort) AddNamedPortByPod(pod *v1.Pod) {
}
n.namedPortMap[ns][port.Name] = &util.NamedPortInfo{
PortId: port.ContainerPort,
Pods: map[string]string{podName: ""},
Pods: map[string]struct{}{podName: {}},
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/named_port.go
Expand Up @@ -2,5 +2,5 @@ package util

type NamedPortInfo struct {
PortId int32
Pods map[string]string // pods named port belong to
Pods map[string]struct{}
}

0 comments on commit 0bd7c7e

Please sign in to comment.