From 99b27cde64d6616a9e41f52f4a699577cf60f1d6 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 27 May 2026 19:20:01 +0100 Subject: [PATCH] perf(sessions): reduce store clone allocations --- src/config/sessions/store-cache.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/config/sessions/store-cache.ts b/src/config/sessions/store-cache.ts index 0499fcc205a5..87fa4c89b4cb 100644 --- a/src/config/sessions/store-cache.ts +++ b/src/config/sessions/store-cache.ts @@ -196,10 +196,21 @@ function cloneJsonLikeValue(value: T): T { return value; } if (Array.isArray(value)) { - return value.map((item) => cloneJsonLikeValue(item)) as T; + const cloned = new Array(value.length); + for (let index = 0; index < value.length; index += 1) { + if (!(index in value)) { + continue; + } + cloned[index] = cloneJsonLikeValue(value[index]); + } + return cloned as T; } const cloned: Record = {}; - for (const [key, child] of Object.entries(value as Record)) { + for (const key in value as Record) { + if (!Object.prototype.hasOwnProperty.call(value, key)) { + continue; + } + const child = (value as Record)[key]; if (child === undefined) { continue; }