From c73bb077bf4ee4d09d462eab331502a1654e9d4c Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 3 Mar 2026 02:40:30 +0000 Subject: [PATCH] perf: optimize array deduplication in backup endpoints - Replace spread operator with iterative Set.add() to avoid intermediate array allocation. - Add conditional assignment to avoid unnecessary updates when no new endpoints are found. - Improve memory efficiency and CPU performance during backup endpoint merging. Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com> --- src/client.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/client.ts b/src/client.ts index 48ad5d1b..cf15021b 100644 --- a/src/client.ts +++ b/src/client.ts @@ -344,9 +344,14 @@ export class Pushy { const remoteEndpoints = await resp.json(); log('fetch endpoints:', remoteEndpoints); if (Array.isArray(remoteEndpoints)) { - server.backups = Array.from( - new Set([...(server.backups || []), ...remoteEndpoints]), - ); + const backups = server.backups || []; + const set = new Set(backups); + for (const endpoint of remoteEndpoints) { + set.add(endpoint); + } + if (set.size !== backups.length) { + server.backups = Array.from(set); + } } } catch (e: any) { log('failed to fetch endpoints from: ', server.queryUrls);