Skip to content

Commit

Permalink
use maps.Equal instead of reflect.DeepEqual
Browse files Browse the repository at this point in the history
reflect causes a lot of memory allocations and uses more CPU time.
maps.Equal does not cause any allocations and is about 80% faster
  • Loading branch information
lrweck authored Jul 23, 2024
1 parent 76c172a commit 55d058a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cluster/informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"google.golang.org/protobuf/types/known/anypb"
"log/slog"
"math/rand"
"reflect"
"maps"
"time"

"github.com/asynkron/gofun/set"
Expand Down Expand Up @@ -211,7 +211,7 @@ func (inf *Informer) GetMemberStateDelta(targetMemberID string) *MemberStateDelt
}
}

hasState := reflect.DeepEqual(inf.committedOffsets, pendingOffsets)
hasState := maps.Equal(inf.committedOffsets, pendingOffsets)
memberState := &MemberStateDelta{
TargetMemberID: targetMemberID,
HasState: hasState,
Expand Down

0 comments on commit 55d058a

Please sign in to comment.