From 382da481809dfe5faa2970e560cccf14bb9b4a60 Mon Sep 17 00:00:00 2001 From: Derek Collison Date: Mon, 25 Sep 2023 13:01:46 -0700 Subject: [PATCH 1/2] The func subjectIsSubsetMatch() is heavy so do without the account lock. Signed-off-by: Derek Collison --- server/accounts.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/accounts.go b/server/accounts.go index 521604f9..ba15dda4 100644 --- a/server/accounts.go +++ b/server/accounts.go @@ -1717,14 +1717,15 @@ func (a *Account) checkForReverseEntries(reply string, checkInterest, recursed b var _rs [64]string rs := _rs[:0] for k := range a.imports.rrMap { - if subjectIsSubsetMatch(k, reply) { - rs = append(rs, k) - } + rs = append(rs, k) } a.mu.RUnlock() + // subjectIsSubsetMatch is heavy so make sure we do this without the lock. for _, r := range rs { - a._checkForReverseEntry(r, nil, checkInterest, recursed) + if subjectIsSubsetMatch(r, reply) { + a._checkForReverseEntry(r, nil, checkInterest, recursed) + } } } From fb4e97e2eca61826b2a0aa3496ddf30a4b4fdb32 Mon Sep 17 00:00:00 2001 From: Derek Collison Date: Mon, 25 Sep 2023 13:12:13 -0700 Subject: [PATCH 2/2] If we know bigger go ahead an allocate. Signed-off-by: Derek Collison --- server/accounts.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/accounts.go b/server/accounts.go index ba15dda4..e7808551 100644 --- a/server/accounts.go +++ b/server/accounts.go @@ -1716,6 +1716,11 @@ func (a *Account) checkForReverseEntries(reply string, checkInterest, recursed b var _rs [64]string rs := _rs[:0] + + if n := len(a.imports.rrMap); n > cap(rs) { + rs = make([]string, 0, n) + } + for k := range a.imports.rrMap { rs = append(rs, k) }