Skip to content

Fix Datetime.{h,cpp} to include cmake.h for HAVE_TIMEGM define#105

Merged
lauft merged 1 commit into
GothenburgBitFactory:masterfrom
smemsh:fix-timegm-cmake
Aug 27, 2025
Merged

Fix Datetime.{h,cpp} to include cmake.h for HAVE_TIMEGM define#105
lauft merged 1 commit into
GothenburgBitFactory:masterfrom
smemsh:fix-timegm-cmake

Conversation

@smemsh

@smemsh smemsh commented Aug 27, 2025

Copy link
Copy Markdown
Contributor

The previous move of Datetime::timegm() into libshared (from Taskwarrior) in PR #99 caused a significant performance regression in Timewarrior because a slow fallback method was used due to -DHAVE_TIMEGM not being picked up from cmake.

That fallback calls tzset() for every timegm() call, which is done twice for every interval in the Timewarrior data, and involves file I/O with /etc/localtime. These calls can number in the tens of thousands even for simple operations, depending on time db size.

This patch includes cmake.h so the HAVE_TIMEGM define can be picked up and we'll defer to the libc implementation of timegm(), which is much faster (it does not do tzset()).

Windows may still be affected by the slowness, it may not have timegm(), but it will continue to work there, and should use the faster libc on BSDs and GNU systems.

Problem described more in GothenburgBitFactory/timewarrior#703 and in #104.

Taskwarrior does not seem to use timegm(), so no need to bump its libshared.

Fixes #104.

There is a preprocessor define to use the system version of timegm()
rather than a [slow] fallback function implemented in libshared.  The
function Datetime::timegm() conditionally manifests if said define is
unset, but the code won't actually consult the value (provided by
cmake), unless we include the cmake header.

(This function is only used by Timewarrior, so Taskwarrior need not peg
to a new libshared just for this fix.)
@lauft lauft merged commit 9682b46 into GothenburgBitFactory:master Aug 27, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bad timew performance regression from timegm relocation into libshared

2 participants