From dbf755968827b0d75f5e30d35a6c90da3cdc1aa2 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 26 Sep 2026 23:11:20 -0700 Subject: Feed scroll: stop re-parsing the whole messages state per row per repaint. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A CPU profile of a 44 s scroll on Adam's tab: 21 of 27 busy seconds in loadFeatureState — every read parsed the multi-megabyte messages blob from localStorage and re-hashed the seed for its key, and the mute/spam checks read it for every row on every repaint. Now the cache key is hashed once per identity, the messages state is parsed once per tick (a write refreshes the copy; the copy is dropped on account switch), and the profile blob stays parsed in memory and is written back once per burst instead of being parsed and re-serialized for each of thirty profiles landing mid-scroll. Videos preload metadata only: a window of autoplaying players was streaming 20 MB during the same scroll. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01VhUKyXKtsJ67QAFfb7QR9D --- src/wallet.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/wallet.js') diff --git a/src/wallet.js b/src/wallet.js index ae9ac1b..9eb2b94 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -1785,8 +1785,13 @@ export class Wallet { _cacheKey() { let id = this.watchOnly ? this.xpub : this.xprv ? this.xprv : `${this.mnemonic}\n${this.passphrase}`; if (this.accountIndex) id += `\n#${this.accountIndex}`; // derived siblings get their own slots + // hashed once per identity: every feature-state read went through here, + // and a feed repaint reads state dozens of times + if (this._cacheKeyFor === id && this._cacheKeyVal) return this._cacheKeyVal; const bytes = new TextEncoder().encode(id); - return 'btc-wallet-cache:' + hex.encode(sha256(bytes)).slice(0, 32); + this._cacheKeyFor = id; + this._cacheKeyVal = 'btc-wallet-cache:' + hex.encode(sha256(bytes)).slice(0, 32); + return this._cacheKeyVal; } // The fresh receive index the "payment received" screen has been shown for. -- cgit v1.2.3