summaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorshamteev <[email protected]>2026-06-16 23:27:30 +0300
committershamteev <[email protected]>2026-06-16 23:54:42 +0300
commit9c0feecb216b98e6e483257cf2b2afafcd7d7c77 (patch)
tree7cba26adc554588f42d7779d484b858bd92e0dbc /library/cpp
parent42a93ecbc67ce6324fcb8e463301883ff214a31f (diff)
Speed up working with timezones
Optimize timezone-aware query functions (timestamp_floor\_\*\_tz, format_timestamp_tz) Problem: queries using timezone functions on a non-Moscow/non-UTC zone (e.g. Europe/Bucharest) ran 10-20x slower than their non-timezone equivalents. For Moscow/UTC a lookup table handles the conversion; for any other zone the code falls back to live cctz calls. Cause, confirmed by flamegraph and code: 1. NDatetime::ToCivilTime performed two independent timezone lookups per call. cctz::convert(tp, tz) is defined as tz.lookup(tp).cs, and the function then called tz.lookup(tp) again for the offset/is_dst fields. Both pieces of data are already present in a single absolute_lookup result. 2. TimestampFloorDayTZInternal (and Month/Quarter/Year variants) located the start of the period via a binary search that called ToCivilTime on every iteration — \~18 iterations for the day case. Combined with (1) that is \~38 cctz lookups per call, and timestamp_floor_day_tz appears twice per row in a typical WHERE clause. * Changelog entry Type: fix 1. ToCivilTime now does a single tz.lookup(tp) and reuses both cs and the offset/is_dst fields. Behavior is identical; affects all callers. 2. TimestampFloor\{Day,Month,Quarter,Year\}TZ compute the period start directly (subtract the civil time-of-day, or build the first second of the period and convert it back), then verify the result. The binary search is kept as a fallback for the rare days that do not start at midnight (DST transitions at 00:00, historical offset shifts), so results are unchanged. commit_hash:295ee82832ab2a4a35920067e7c063d6992bb083
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/timezone_conversion/convert.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/library/cpp/timezone_conversion/convert.cpp b/library/cpp/timezone_conversion/convert.cpp
index 490bb4e2700..2bec10eccfa 100644
--- a/library/cpp/timezone_conversion/convert.cpp
+++ b/library/cpp/timezone_conversion/convert.cpp
@@ -72,7 +72,8 @@ namespace NDatetime {
TSimpleTM ToCivilTime(const TInstant& absoluteTime, const TTimeZone& tz) {
TTimePoint tp = TSystemClock::from_time_t(absoluteTime.TimeT());
- return CivilToTM(cctz::convert(tp, tz), tz.lookup(tp));
+ auto al = tz.lookup(tp);
+ return CivilToTM(al.cs, al);
}
TSimpleTM CreateCivilTime(const TTimeZone& tz, ui32 year, ui32 mon, ui32 day, ui32 h, ui32 m, ui32 s) {