From 94a014790b8c4b67e83bd3c2fb3b31a4f3142495 Mon Sep 17 00:00:00 2001 From: Boris Yankov Date: Wed, 8 Jan 2025 02:29:17 +0200 Subject: [PATCH 1/2] perf: do 'lazy' comparison in 'checkIfCacheDataOutdated' Simplifies comparison with cached data. Also does not 'precompute' it before doing the comparison, so expression terminates on first difference. --- .../repack/src/modules/ScriptManager/Script.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/repack/src/modules/ScriptManager/Script.ts b/packages/repack/src/modules/ScriptManager/Script.ts index d92f83f93..95cf06440 100644 --- a/packages/repack/src/modules/ScriptManager/Script.ts +++ b/packages/repack/src/modules/ScriptManager/Script.ts @@ -213,15 +213,13 @@ export class Script { 'method' | 'url' | 'query' | 'headers' | 'body' > ) { - const diffs = [ - cachedData.method !== this.locator.method, - cachedData.url !== this.locator.url, - cachedData.query !== this.locator.query, - !shallowEqual(cachedData.headers, this.locator.headers), - cachedData.body !== this.locator.body, - ]; - - return diffs.some((diff) => diff); + return ( + cachedData.method !== this.locator.method || + cachedData.url !== this.locator.url || + cachedData.query !== this.locator.query || + !shallowEqual(cachedData.headers, this.locator.headers) || + cachedData.body !== this.locator.body + ); } /** From 35aa7ce2f12ea3d2b56b4cad937478323c2a2e0e Mon Sep 17 00:00:00 2001 From: Boris Yankov Date: Thu, 9 Jan 2025 00:47:19 +0200 Subject: [PATCH 2/2] chore: add changeset --- .changeset/tricky-keys-kneel.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tricky-keys-kneel.md diff --git a/.changeset/tricky-keys-kneel.md b/.changeset/tricky-keys-kneel.md new file mode 100644 index 000000000..e038f1763 --- /dev/null +++ b/.changeset/tricky-keys-kneel.md @@ -0,0 +1,5 @@ +--- +"@callstack/repack": minor +--- + +Optimize 'checkIfCacheDataOutdated' to do as few comparisons as possible