Rust's `time` Crate Gets a 57.5% Speed Boost with a Rewritten Algorithm

2025-02-03

After five years of maintaining the Rust `time` crate, the author undertook a major performance optimization. By redesigning the `Date::to_calendar_date` algorithm, leveraging Euclidean affine functions and clever integer arithmetic, the author avoided floating-point operations and branching, resulting in a 57.5% performance improvement. The new algorithm is significantly faster not only when calculating both date and month together but also when calculating them separately. This was a non-trivial undertaking, but the author believes the performance gains are well worth the effort.

Development