Understand the performance characteristics of whenever
mainThe whenever library is designed with a balanced approach to three competing goals:
- Runtime speed: Optimized via a Rust extension that uses hand-written, single-pass byte-level parsers and formatters (avoiding regex and intermediate string objects) and front-loaded computation (storing UTC offsets at construction time).
- Import time: Minimized using lazy loading. The
__init__.pyuses PEP 562 (__getattr__) to defer loading the Rust extension and dependencies (datetime,zoneinfo,pydantic,typing) until they are actually accessed. - Package size: Kept reasonable by implementing non-critical types (like
Weekday,YearMonth,MonthDay,IsoWeekDate) in pure Python, even when the Rust extension is active.
Note on Pure-Python Fallback: If you are using the pure-Python version instead of the Rust extension:
- It is faster than Arrow and Pendulum for simple operations like
now(), ISO parsing, and UTC normalization. - It is slower for timezone-heavy operations (like
ZonedDateTimeconstruction or conversion) because it relies on pure-Python timezone code instead of the C-optimizedzoneinfomodule.