Skip to content

Commit 3b901cb

Browse files
milan-zededaeriknordmark
authored andcommitted
Avoid using expensive reflect for the Bond.Equal method
reflect.DeepEqual is quite expensive so let's compare Bond fields manually and using more efficient methods from the generics package. Signed-off-by: Milan Lenco <[email protected]> (cherry picked from commit a783bfc)
1 parent 5497994 commit 3b901cb

File tree

1 file changed

+11
-5
lines changed
  • pkg/pillar/dpcreconciler/linuxitems

1 file changed

+11
-5
lines changed

pkg/pillar/dpcreconciler/linuxitems/bond.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ package linuxitems
66
import (
77
"context"
88
"fmt"
9-
"reflect"
10-
119
"github.com/vishvananda/netlink"
1210

1311
"github.com/lf-edge/eve-libs/depgraph"
1412
"github.com/lf-edge/eve/pkg/pillar/base"
1513
"github.com/lf-edge/eve/pkg/pillar/dpcreconciler/genericitems"
1614
"github.com/lf-edge/eve/pkg/pillar/netmonitor"
1715
"github.com/lf-edge/eve/pkg/pillar/types"
16+
"github.com/lf-edge/eve/pkg/pillar/utils/generics"
1817
)
1918

2019
// Bond : Bond interface.
@@ -52,8 +51,12 @@ func (b Bond) Type() string {
5251
// Equal is a comparison method for two equally-named Bond instances.
5352
func (b Bond) Equal(other depgraph.Item) bool {
5453
b2 := other.(Bond)
55-
return reflect.DeepEqual(b.BondConfig, b2.BondConfig) &&
56-
reflect.DeepEqual(b.AggregatedIfNames, b2.AggregatedIfNames) &&
54+
return b.LacpRate == b2.LacpRate &&
55+
b.MIIMonitor == b2.MIIMonitor &&
56+
b.Mode == b2.Mode &&
57+
b.ARPMonitor.Equal(b2.ARPMonitor) &&
58+
generics.EqualSets(b.AggregatedIfNames, b2.AggregatedIfNames) &&
59+
b.Usage == b2.Usage &&
5760
b.MTU == b2.MTU
5861
}
5962

@@ -320,7 +323,10 @@ func (c *BondConfigurator) Delete(ctx context.Context, item depgraph.Item) error
320323
func (c *BondConfigurator) NeedsRecreate(oldItem, newItem depgraph.Item) (recreate bool) {
321324
oldBondCfg := oldItem.(Bond)
322325
newBondCfg := newItem.(Bond)
323-
if !reflect.DeepEqual(oldBondCfg.BondConfig, newBondCfg.BondConfig) {
326+
if oldBondCfg.LacpRate != newBondCfg.LacpRate ||
327+
oldBondCfg.MIIMonitor != newBondCfg.MIIMonitor ||
328+
oldBondCfg.Mode != newBondCfg.Mode ||
329+
!oldBondCfg.ARPMonitor.Equal(newBondCfg.ARPMonitor) {
324330
return true
325331
}
326332
if oldBondCfg.Usage != newBondCfg.Usage {

0 commit comments

Comments
 (0)