From 55d058a3fabf7d6671720e67dc88f7396715d6b2 Mon Sep 17 00:00:00 2001 From: Luis Date: Tue, 23 Jul 2024 09:28:31 -0300 Subject: [PATCH] use maps.Equal instead of reflect.DeepEqual reflect causes a lot of memory allocations and uses more CPU time. maps.Equal does not cause any allocations and is about 80% faster --- cluster/informer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cluster/informer.go b/cluster/informer.go index 4118aa37..ce364313 100644 --- a/cluster/informer.go +++ b/cluster/informer.go @@ -7,7 +7,7 @@ import ( "google.golang.org/protobuf/types/known/anypb" "log/slog" "math/rand" - "reflect" + "maps" "time" "github.com/asynkron/gofun/set" @@ -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,