Optimize local time printing using new formatters - #2439
Open
Menkib64 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
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 cachedcurrent_zone()+std::formatfor faster local time formatting when available.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I noticed that FormatTime took about 20 µs which is called from
SearchWorkerthread 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 cachingcurrent_zone()result which takes over 10 µs each time called.