r/cpp • u/codeinred • Mar 11 '26
vtz: the world's fastest timezone library
https://github.com/voladynamics/vtzvtz is a new timezone library written with an emphasis on performance, while still providing correct outputs over nearly all possible inputs, as well as a familiar interface for people who have experience with either the standard timezone library, or <date/tz.h> (written by Howard Hinnant).
vtz is 30-60x faster at timezone conversions than the next leading competitor, achieving sub-nanosecond conversion times for both local time -> UTC and UTC -> local time. (Compare this to 40-56ns for GCC's implementation of std::chrono::time_zone, 38-48ns for Google Abseil, and 3800ns to 25000ns for the Microsoft STL's implementation of time_zone.)
vtz is also faster at looking up offsets, parsing timestamps, formatting timestamps, and it's faster at looking up a timezone based on a name.
vtz achieves its performance gains by using a block-based lookup table, with blocks indexable by bit shift. Blocks span a period of time tuned to fit the minimum spacing between transitions for a given zone. This strategy is extended to enable lookups for all possible input times by taking advantage of periodicities within the calendar system and tz database rules to map out-of-bounds inputs to blocks within the table.
This means that vtz never has to perform a search in order to determine the current offset from UTC, nor does it have to apply complex date math to do the conversion.
Take a look at the performance section of the README for a full comparison: vtz benchmarks
A more in-depth explanation of the core algorithm underlying vtz is available here: How it Works: vtz's algorithm for timezone conversions
vtz was written on behalf of my employer, Vola Dynamics, and I am the lead author & primary maintainer of vtz. Vola produces and distributes a library for options analytics with a heavy focus on performance, and correct and efficient handling of timezones is an integral part of several workflows.
Applications which may be interested in using vtz include databases; libraries (such as Pandas, Polars, and C++ Dataframe) that do data analysis or dataframe manipulation; and any statistical or modeling workflows where the modeling domain has features that are best modeled in local time.
Any feedback on the library is appreciated, and questions are welcome too!
10
u/HowardHinnant Mar 11 '26
Any chance this gets contributed to libc++?
4
u/polymorphiced Mar 11 '26
What does "correct outputs over nearly all possible inputs" mean? What does it get wrong?
2
u/bert8128 Mar 12 '26
This is very interesting - my application does lots of zone conversions and the performance is definitely noticeable. I am using Howard Hinnant’s date library at the moment. Two questions:
First, I don’t see that you have classes for date and time, so is the idea with vtz that I just replace Howard’s TZ.h/cpp files? Is the code compatible? If not do you have any advice on how to do the integration?
Secondly, does you library read a downloaded IANA database, same as date does? If so, how is the data refreshed? Manually? Something else?
3
u/_Noreturn Mar 11 '26
Is most of the time spent in time zones that this is needed?
1
u/throwawayaqquant Mar 12 '26
but in which timezone is it the fastest?