Skip to content

Optimize local time printing using new formatters - #2439

Open
Menkib64 wants to merge 2 commits into
LeelaChessZero:masterfrom
Menkib64:local_time_print_optimization
Open

Optimize local time printing using new formatters#2439
Menkib64 wants to merge 2 commits into
LeelaChessZero:masterfrom
Menkib64:local_time_print_optimization

Conversation

@Menkib64

@Menkib64 Menkib64 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

I noticed that FormatTime took about 20 µs which is called from SearchWorker thread when sending uci infos. I decided to check if it could be done faster. The new chrono and formatter based approach manages to reduce it to about 8 µs. The gain is mainly from caching current_zone() result which takes over 10 µs each time called.

Copilot AI lite review requested due to automatic review settings August 7, 2026 15:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes log timestamp formatting by using C++20 <format>/chrono time zone formatting and caching std::chrono::current_zone() to reduce per-call overhead in hot paths (e.g., UCI info emission from search threads).

Changes:

  • Add feature-gated includes for <format> and <chrono> (via <version> feature-test macros).
  • Update FormatTime() to use cached current_zone() + std::format for faster local time formatting when available.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/utils/logging.cc
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.

2 participants