Skip to content

Fix app hang during date formatting by pre-warming locale cache#438

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/app-hang-locale-cache
Open

Fix app hang during date formatting by pre-warming locale cache#438
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/app-hang-locale-cache

Conversation

@sentry

@sentry sentry Bot commented Jul 9, 2026

Copy link
Copy Markdown

This PR addresses an app hanging issue (REPOPROMPT-8) where the application would freeze for 2000ms+ on macOS 26.x.

Root Cause:
The hang was traced to synchronous, expensive ICU (International Components for Unicode) locale processing occurring on the main thread. Specifically, the MessageTimestampFormatter's setLocalizedDateFormatFromTemplate(_:) call, triggered during SwiftUI rendering, would block the main thread while inferring locale subtags (ulocimp_addLikelySubtags -> RegionValidateMap::equals -> res_getTableItemByKey). This was particularly noticeable on macOS 26.x, suggesting changes in ICU data loading behavior.

Solution:
To prevent this main thread blockage, the MessageTimestampFormatter's cache is now pre-warmed on a background thread during application startup. This ensures that when the main thread first requests a formatted timestamp, the expensive DateFormatter and RelativeDateTimeFormatter instances, along with their underlying ICU data, have already been initialized and cached.

Changes Made:

  • Added a warmUp() static method to MessageTimestampFormatter to explicitly pre-populate its internal DateFormatter and RelativeDateTimeFormatter caches for all commonly used formats and templates.
  • Integrated a call to MessageTimestampFormatter.warmUp() within a Task.detached(priority: .utility) in RepoPromptApp.init(). This executes the pre-warming on a background thread, preventing UI freezes.

The existing NSLock in MessageTimestampFormatterCache ensures thread-safe access during concurrent initialization and subsequent main-thread usage.

Fixes REPOPROMPT-8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants