From 4e0656f377bb520b315f4770f603929b34c5f625 Mon Sep 17 00:00:00 2001 From: Derek Collison Date: Tue, 26 Sep 2023 18:20:40 -0700 Subject: [PATCH] Small performance tweak to checkForReverseEntries. Signed-off-by: Derek Collison --- server/accounts.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/server/accounts.go b/server/accounts.go index e7808551..c26c09a1 100644 --- a/server/accounts.go +++ b/server/accounts.go @@ -1702,21 +1702,19 @@ func (a *Account) addReverseRespMapEntry(acc *Account, reply, from string) { // This will be called from checkForReverseEntry when the reply arg is a wildcard subject. // This will usually be called in a go routine since we need to walk all the entries. func (a *Account) checkForReverseEntries(reply string, checkInterest, recursed bool) { + if subjectIsLiteral(reply) { + a._checkForReverseEntry(reply, nil, checkInterest, recursed) + return + } + a.mu.RLock() if len(a.imports.rrMap) == 0 { a.mu.RUnlock() return } - if subjectIsLiteral(reply) { - a.mu.RUnlock() - a._checkForReverseEntry(reply, nil, checkInterest, recursed) - return - } - var _rs [64]string rs := _rs[:0] - if n := len(a.imports.rrMap); n > cap(rs) { rs = make([]string, 0, n) } @@ -1726,9 +1724,14 @@ func (a *Account) checkForReverseEntries(reply string, checkInterest, recursed b } a.mu.RUnlock() - // subjectIsSubsetMatch is heavy so make sure we do this without the lock. + tsa := [32]string{} + tts := tokenizeSubjectIntoSlice(tsa[:0], reply) + + rsa := [32]string{} for _, r := range rs { - if subjectIsSubsetMatch(r, reply) { + rts := tokenizeSubjectIntoSlice(rsa[:0], r) + // isSubsetMatchTokenized is heavy so make sure we do this without the lock. + if isSubsetMatchTokenized(rts, tts) { a._checkForReverseEntry(r, nil, checkInterest, recursed) } }