From d0d8244768f0ee4580ae98c61207b6c3e2000700 Mon Sep 17 00:00:00 2001 From: Thomas Bertet Date: Fri, 6 Mar 2026 17:57:21 +0100 Subject: [PATCH 1/2] =?UTF-8?q?[PROF-13950]=20=E2=9A=A1=EF=B8=8F=20Memoize?= =?UTF-8?q?=20getTimeZone=20to=20avoid=20repeated=20Intl.DateTimeFormat=20?= =?UTF-8?q?instantiation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit new Intl.DateTimeFormat() is expensive (locale negotiation + timezone resolution) and was called on every VIEW_UPDATED event. Since the timezone is static for the page lifetime, compute it once at module load time instead. --- packages/core/src/tools/utils/timezone.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/core/src/tools/utils/timezone.ts b/packages/core/src/tools/utils/timezone.ts index a2900f7b2b..8ce9305915 100644 --- a/packages/core/src/tools/utils/timezone.ts +++ b/packages/core/src/tools/utils/timezone.ts @@ -1,9 +1,13 @@ -export function getTimeZone() { +function resolveTimeZone() { try { - const intl = new Intl.DateTimeFormat() - - return intl.resolvedOptions().timeZone + return new Intl.DateTimeFormat().resolvedOptions().timeZone } catch { return undefined } } + +const timeZone = resolveTimeZone() + +export function getTimeZone() { + return timeZone +} From 6b7b26026fa4db080c5fb83f32bfcf752335cb98 Mon Sep 17 00:00:00 2001 From: Thomas Bertet Date: Mon, 9 Mar 2026 17:41:57 +0100 Subject: [PATCH 2/2] =?UTF-8?q?[PROF-13950]=20=E2=9A=A1=EF=B8=8F=20Use=20l?= =?UTF-8?q?azy=20initialization=20for=20getTimeZone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switch from eager module-level computation to lazy caching: compute the timezone on first call and cache it, avoiding any cost at module load time. --- packages/core/src/tools/utils/timezone.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/core/src/tools/utils/timezone.ts b/packages/core/src/tools/utils/timezone.ts index 8ce9305915..6250d90f96 100644 --- a/packages/core/src/tools/utils/timezone.ts +++ b/packages/core/src/tools/utils/timezone.ts @@ -1,13 +1,12 @@ -function resolveTimeZone() { - try { - return new Intl.DateTimeFormat().resolvedOptions().timeZone - } catch { - return undefined - } -} - -const timeZone = resolveTimeZone() +let cachedTimeZone: string | undefined | null = null export function getTimeZone() { - return timeZone + if (cachedTimeZone === null) { + try { + cachedTimeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone + } catch { + cachedTimeZone = undefined + } + } + return cachedTimeZone }