Skip to content

perf: lazily resolve the local timezone - #909

Open
efegokdemir wants to merge 7 commits into
sharkdp:mainfrom
efegokdemir:fix-650-lazy-local-timezone
Open

efegokdemir wants to merge 7 commits into
sharkdp:mainfrom
efegokdemir:fix-650-lazy-local-timezone

Conversation

@efegokdemir

Copy link
Copy Markdown

Summary

Addresses #650.

  • Replace the eager tz(get_local_timezone()) initialization with a lightweight _local() FFI function.
  • Resolve the system timezone only when the resulting conversion function is used.
  • Preserve the existing datetime -> local syntax and output.
  • Add a regression test and update the affected snapshot.

This follows the lightweight FFI-wrapper approach suggested in the issue discussion, without introducing general-purpose lazy evaluation.

Validation

  • cargo fmt --all -- --check
  • cargo test --workspace
  • git diff --check
  • Compared six expressions against the original binary; all outputs and exit statuses matched.

Local benchmark

Paired measurements of numbat -e '1 + 1' on one Mac, using debug builds:

  • Before: median 187.99 ms
  • After: median 186.38 ms
  • Difference: 1.61 ms (0.9%)

These measurements include full process startup. The observed improvement is modest, and the benchmark does not establish statistical significance.

Opening as a draft for implementation review and CI validation.

@efegokdemir
efegokdemir marked this pull request as ready for review September 19, 2026 01:08
Signed-off-by: Efe Gökdemir <efe@rexcode.co.uk>
@efegokdemir

Copy link
Copy Markdown
Author

The failing musl targets exposed a real portability issue: TimeZone::system() can have no IANA name when timezone data is unavailable, while the new regression compared it with tz(get_local_timezone()). Commit 9e4761d makes the existing get_local_timezone_or_utc() fallback explicit: named system zones are preserved, otherwise both local conversion and the exposed timezone use UTC.

Validation: cargo test -p numbat --test interpreter test_lazy_local_timezone_conversion passed, cargo fmt --all passed, and git diff --check passed. The commit is DCO-signed and GitHub-verified. The full workflow is rerunning.

Keep release builds unchanged while avoiding native i686 socketpair
ENOSYS on hosted runners. Preserve all test assertions.
Replace map_or(default, identity) with equivalent unwrap_or(default)
without suppressing current Clippy warnings.
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.

1 participant