Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Sources/RepoPrompt/App/RepoPromptApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ struct RepoPromptApp: App {
// Avoid process-killing SIGPIPE when the child closes stdin while we're still writing.
signal(SIGPIPE, SIG_IGN)

// Pre-warm date formatter cache on a background thread to avoid blocking the main
// thread with ICU locale processing (ulocimp_addLikelySubtags) on first render.
Task.detached(priority: .utility) {
MessageTimestampFormatter.warmUp()
}

SentryTelemetryBootstrap.start()

ProcessDebugLogging.log(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ import Foundation
enum MessageTimestampFormatter {
private static let cache = MessageTimestampFormatterCache()

/// Pre-warms the formatter cache on a background thread so that the first call from
/// the main thread (during SwiftUI rendering) does not block on expensive ICU locale
/// processing (ulocimp_addLikelySubtags / setLocalizedDateFormatFromTemplate).
static func warmUp() {
let calendar = Calendar.current
let locale = Locale.current
let now = Date()
// Touch every format / template variant the formatter can produce.
_ = cache.string(from: now, format: "HH:mm:ss", calendar: calendar, locale: locale)
for template in ["EEE", "MMM d", "MMM d y"] {
_ = cache.string(from: now, template: template, calendar: calendar, locale: locale)
}
_ = cache.relativeDayLabel(-1, calendar: calendar, locale: locale)
}

static func string(
from date: Date,
includeDateContext: Bool,
Expand Down
Loading