perf(chat): use reentrant local time for chat timestamps
The open chat thread called std::localtime at least twice per message per frame (two day keys for grouping), and more for day separators and time labels. On glibc every call re-checks the timezone with a stat of /etc/localtime. The chat time helpers now use util::localTime() from the new util/local_time.h: localtime_r (localtime_s on Windows), with no per-call timezone check and no shared static result buffer. glibc's localtime_r reads the timezone only once, so local_time.h also adds util::refreshTimezone() (tzset) for caches to call when they rebuild. Nothing calls it yet; its first caller is the chat thread's grouping-flags cache in the next commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
// DragonX Wallet - reentrant local-time helper (no per-call stat of /etc/localtime on glibc).
|
||||
#pragma once
|
||||
#include <ctime>
|
||||
namespace dragonx::util {
|
||||
// Fills `out` with the local broken-down time of `t`. Returns false on failure. Thread-safe.
|
||||
inline bool localTime(std::time_t t, std::tm& out) {
|
||||
#ifdef _WIN32
|
||||
return localtime_s(&out, &t) == 0;
|
||||
#else
|
||||
return localtime_r(&t, &out) != nullptr;
|
||||
#endif
|
||||
}
|
||||
// Re-read the TZ database / TZ env (glibc localtime_r does not do this on its own after the first call).
|
||||
// Call once per cache rebuild, never per item.
|
||||
inline void refreshTimezone() {
|
||||
#ifdef _WIN32
|
||||
_tzset();
|
||||
#else
|
||||
tzset();
|
||||
#endif
|
||||
}
|
||||
} // namespace dragonx::util
|
||||
Reference in New Issue
Block a user