From 04c181fe277005e031a6b584b47e31d8fe9820b6 Mon Sep 17 00:00:00 2001 From: Neil Twigg Date: Fri, 2 Aug 2024 13:30:47 +0100 Subject: [PATCH] Optimise `getAccAndResultFromCache` by reducing allocations We'll still copy the string when asking the resolver, as we can't be sure whether a resolver will want to hold onto the string or not, but this should lead to improvements on the hot paths for routes and gateways when the cache doesn't contain the entries we want. Signed-off-by: Neil Twigg --- server/accounts.go | 2 +- server/client.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/accounts.go b/server/accounts.go index 3217d5cf8f..33f926b10c 100644 --- a/server/accounts.go +++ b/server/accounts.go @@ -3869,7 +3869,7 @@ func fetchAccount(res AccountResolver, name string) (string, error) { if !nkeys.IsValidPublicAccountKey(name) { return _EMPTY_, fmt.Errorf("will only fetch valid account keys") } - return res.Fetch(name) + return res.Fetch(copyString(name)) } // AccountResolver interface. This is to fetch Account JWTs by public nkeys diff --git a/server/client.go b/server/client.go index e5b08c3f42..be1f72ef10 100644 --- a/server/client.go +++ b/server/client.go @@ -5668,7 +5668,7 @@ func (c *client) getAccAndResultFromCache() (*Account, *SublistResult) { } } else { // Match correct account and sublist. - if acc, _ = c.srv.LookupAccount(string(c.pa.account)); acc == nil { + if acc, _ = c.srv.LookupAccount(bytesToString(c.pa.account)); acc == nil { return nil, nil } }