From e0f53a704e68d707f252c0d8ef1b99897f54ea3b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 8 Jul 2026 14:29:23 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20[performance]=20Optimize=20pendingS?= =?UTF-8?q?ubscribersInternal=20allocation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract pendingState.get() evaluation outside of the pendingSubscribersInternal.forEach loop to avoid redundant object allocations. Co-authored-by: johnstrand <11484777+johnstrand@users.noreply.github.com> --- src/Squawk.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Squawk.ts b/src/Squawk.ts index 01a0b5d..5ca6e33 100644 --- a/src/Squawk.ts +++ b/src/Squawk.ts @@ -271,7 +271,10 @@ export default function createStore(initialState: Required, useReduxDevToo } // Invoke all unique subscribers with the new pending states - pendingSubscribersInternal.forEach((subscriber) => subscriber(pendingState.get())); + if (pendingSubscribersInternal.size > 0) { + const currentPendingState = pendingState.get(); + pendingSubscribersInternal.forEach((subscriber) => subscriber(currentPendingState)); + } }, /** Sets up a subscription for a single global state context */ subscribe(context: TContext, callback: Callback): () => void {