From 02ba0adbae43a9a50e420ffb0dab045326721d3b Mon Sep 17 00:00:00 2001 From: Sucukdeluxe <259325684+Sucukdeluxe@users.noreply.github.com> Date: Sat, 26 Sep 2026 10:18:58 +0200 Subject: [PATCH] Speed up language switching by caching date formatters formatDateTime created two Intl formatters per call. Re-formatting 13,000 history rows on a language switch froze the window for more than a second. Cached formatters produce identical output in about 25 ms. --- renderer/app.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/renderer/app.js b/renderer/app.js index 88a2384..6c4c779 100644 --- a/renderer/app.js +++ b/renderer/app.js @@ -10090,13 +10090,27 @@ function formatTime(seconds) { function pad(n) { return String(Math.floor(n)).padStart(2, '0'); } +const _dateTimeFormatters = new Map(); + +function getDateTimeFormatters(locale) { + let formatters = _dateTimeFormatters.get(locale); + if (!formatters) { + formatters = { + date: new Intl.DateTimeFormat(locale, { day: '2-digit', month: '2-digit', year: 'numeric' }), + time: new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit', second: '2-digit' }) + }; + _dateTimeFormatters.set(locale, formatters); + } + return formatters; +} + function formatDateTime(value) { const date = value instanceof Date ? value : new Date(value); if (Number.isNaN(date.getTime())) return { ts: 0, text: localizeUiText('Unbekannt') }; + const formatters = getDateTimeFormatters(getUiLocale()); return { ts: date.getTime(), - text: date.toLocaleDateString(getUiLocale(), { day: '2-digit', month: '2-digit', year: 'numeric' }) - + ' ' + date.toLocaleTimeString(getUiLocale(), { hour: '2-digit', minute: '2-digit', second: '2-digit' }) + text: formatters.date.format(date) + ' ' + formatters.time.format(date) }; }