-
Notifications
You must be signed in to change notification settings - Fork 189
Improve performance of FormatStyle formatting when used in multithreaded context #719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of FormatStyle formatting when used in multithreaded context #719
Conversation
@swift-ci test |
} | ||
// MARK: Singletons | ||
|
||
static let autoupdatingCurrent = _CalendarAutoupdating() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example - this does not need to be stored in the cache, which requires accessing the lock in order to get it.
internal import Synchronization | ||
#endif | ||
|
||
/// Keeps a global generation count for updated Locale information, including locale, time zone, and calendar preferences. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new type stores the info about when we need to reset caches, due to system changes.
Sources/FoundationInternationalization/Formatting/Number/ICUNumberFormatter.swift
Show resolved
Hide resolved
@swift-ci test |
It seems the macOS failure is relevant? |
Sources/FoundationInternationalization/Formatting/Number/ICUNumberFormatter.swift
Show resolved
Hide resolved
return calendar | ||
var calendar = Calendar(identifier: calendarIdentifier) | ||
|
||
if let prefs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm... previously we always access prefs
inside the lock, but not anymore. I can see that this would indeed help speeding it up
} | ||
static let cache = CalendarCache() | ||
|
||
// The values stored in these two locks do not depend upon each other, so it is safe to access them with separate locks. This helps avoids contention on a single lock. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice nice
CalendarCache.cache.reset() | ||
#if FOUNDATION_FRAMEWORK | ||
if let oldDefaultTimeZone { | ||
let noteName = CFNotificationName(rawValue: "kCFTimeZoneSystemTimeZoneDidChangeNotification-2" as CFString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where was this moved to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have one blocking question about time zone notification. The rest looks great
@swift-ci please test |
Improves the performance of formatting dates and times, especially when used in multithreaded contexts.
This patch reworks some of the caching in the Locale, TimeZone, and Calendar types to more efficiently store the singleton values.
Before
After