Timezone database loading: calculate DST save adjustment upfront
Improves performance of timezone lookups after the first call by pre-calculating DST offsets.
This change optimizes timezone handling in libstdc++ by calculating daylight saving time (DST) save adjustments when the timezone database is loaded, rather than on-demand. Previously, calculating these adjustments could incur a performance cost on subsequent lookups, even with caching. By performing the calculation during the initial database load, subsequent calls to retrieve time zone information are faster, though the initial load time increases slightly.
In Details
The tzdb loading mechanism in libstdc++ (chrono::reload_tzdb) now preemptively calls ZoneInfo::calc_save for all zones. This function computes the DST offset. Previously, this was deferred to time_zone::_M_get_sys_info, leading to repeated iterator adjustment checks on cached results. Moving the calculation to load time amortizes this cost, improving performance for repeated, cached timezone queries at the expense of a slightly longer initial load.
- tzdb
- The timezone database, containing information about time zones, historical time and DST changes, and political boundaries for timekeeping.
- Daylight Saving Time (DST)
- A practice of advancing clocks during warmer months so that darkness falls at a later hour of the clock. The 'save' adjustment refers to the amount of time DST shifts the clock forward.