From 16a7097fa2facdafc9849d93ac22f8dd98a1ab85 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Sat, 21 Nov 2026 02:07:27 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20cache=20notification=20time?= =?UTF-8?q?zone=20formatters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pm-stack/aggregator/src/notifications.ts | 25 +++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/pm-stack/aggregator/src/notifications.ts b/pm-stack/aggregator/src/notifications.ts index 667358dd6b..c6b1d31e3c 100644 --- a/pm-stack/aggregator/src/notifications.ts +++ b/pm-stack/aggregator/src/notifications.ts @@ -225,16 +225,23 @@ interface LocalClock { minute: number; } +// ⚡ Bolt: formatter construction (~29µs) dominated repeated digest clock +// conversions. Reuse the immutable formatter for each timezone. +const LOCAL_CLOCK_FORMATTERS = new Map(); +function localClockFormatter(timeZone: string): Intl.DateTimeFormat { + let fmt = LOCAL_CLOCK_FORMATTERS.get(timeZone); + if (!fmt) { + fmt = new Intl.DateTimeFormat("en-US", { + timeZone, year: "numeric", month: "2-digit", day: "2-digit", + hour: "2-digit", minute: "2-digit", hourCycle: "h23", + }); + LOCAL_CLOCK_FORMATTERS.set(timeZone, fmt); + } + return fmt; +} + function localClock(at: number, timeZone: string): LocalClock { - const parts = new Intl.DateTimeFormat("en-US", { - timeZone, - year: "numeric", - month: "2-digit", - day: "2-digit", - hour: "2-digit", - minute: "2-digit", - hourCycle: "h23", - }).formatToParts(new Date(at)); + const parts = localClockFormatter(timeZone).formatToParts(new Date(at)); const value = (type: Intl.DateTimeFormatPartTypes) => Number(parts.find((part) => part.type === type)?.value); return { year: value("year"),