From 1081c067c19c5f1a1dfa2c8ca0d985fc64527855 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 10 Jul 2026 20:38:37 +0000 Subject: [PATCH 1/2] perf: optimize forEach loop in squawk notifications Co-authored-by: johnstrand <11484777+johnstrand@users.noreply.github.com> --- benchmark.ts | 22 ++++++++++++++++++++++ src/Squawk.ts | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 benchmark.ts diff --git a/benchmark.ts b/benchmark.ts new file mode 100644 index 0000000..387542b --- /dev/null +++ b/benchmark.ts @@ -0,0 +1,22 @@ +import createStore from "./src/Squawk"; + +const store = createStore({ foo: 1, bar: "test" }); + +let callCount = 0; +const cb = (val: any) => { callCount++; }; + +// Subscribe many callbacks +for (let i = 0; i < 10000; i++) { + store.subscribe("foo", cb); +} + +const start = Date.now(); + +for (let i = 0; i < 1000; i++) { + store.update({ foo: i }); +} + +const end = Date.now(); + +console.log(`Call count: ${callCount}`); +console.log(`Time taken: ${end - start}ms`); diff --git a/src/Squawk.ts b/src/Squawk.ts index 0355076..61ac96b 100644 --- a/src/Squawk.ts +++ b/src/Squawk.ts @@ -118,7 +118,9 @@ export default function createStore(initialState: Required, useReduxDevToo // We avoid doing forEach(... => { }) because that would recreate the closure for // each loop, and that causes unnecessary allocations for (const list of contextSubscribers) { - list.forEach(reduceEach); + for (const subscriber of list) { + reduceEach(subscriber); + } } }; From 55ab8b1e075096b8d1c382faf86fe1d37e6d05e1 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 10 Jul 2026 20:40:15 +0000 Subject: [PATCH 2/2] chore: remove benchmark.ts outside rootDir Co-authored-by: johnstrand <11484777+johnstrand@users.noreply.github.com> --- benchmark.ts | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 benchmark.ts diff --git a/benchmark.ts b/benchmark.ts deleted file mode 100644 index 387542b..0000000 --- a/benchmark.ts +++ /dev/null @@ -1,22 +0,0 @@ -import createStore from "./src/Squawk"; - -const store = createStore({ foo: 1, bar: "test" }); - -let callCount = 0; -const cb = (val: any) => { callCount++; }; - -// Subscribe many callbacks -for (let i = 0; i < 10000; i++) { - store.subscribe("foo", cb); -} - -const start = Date.now(); - -for (let i = 0; i < 1000; i++) { - store.update({ foo: i }); -} - -const end = Date.now(); - -console.log(`Call count: ${callCount}`); -console.log(`Time taken: ${end - start}ms`);