From 7c5d2a45da3b1e5fd25006cda9e6fc534bc101cf Mon Sep 17 00:00:00 2001 From: wit liu <765765346@qq.com> Date: Wed, 8 Oct 2025 12:50:48 +0800 Subject: [PATCH] accounts/keystore: use ticker to avoid timer allocations #32732 (#1592) --- accounts/keystore/keystore.go | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/accounts/keystore/keystore.go b/accounts/keystore/keystore.go index e03d2582f2..677d1d7c5f 100644 --- a/accounts/keystore/keystore.go +++ b/accounts/keystore/keystore.go @@ -196,23 +196,17 @@ func (ks *KeyStore) Subscribe(sink chan<- accounts.WalletEvent) event.Subscripti // forces a manual refresh (only triggers for systems where the filesystem notifier // is not running). func (ks *KeyStore) updater() { - // Create a timer for the wallet refresh cycle - timer := time.NewTimer(walletRefreshCycle) - defer timer.Stop() + ticker := time.NewTicker(walletRefreshCycle) + defer ticker.Stop() for { // Wait for an account update or a refresh timeout select { case <-ks.changes: - // Stop the timer if we receive an account update before the timer fires - if !timer.Stop() { - <-timer.C - } - case <-timer.C: + case <-ticker.C: } // Run the wallet refresher ks.refreshWallets() - // If all our subscribers left, stop the updater ks.mu.Lock() if ks.updateScope.Count() == 0 { @@ -221,9 +215,6 @@ func (ks *KeyStore) updater() { return } ks.mu.Unlock() - - // Reset the timer for the next cycle - timer.Reset(walletRefreshCycle) } }