Optimize compile times by isolating chrono usage

- move chrono implementation details out of the public Clock header
  - define Sys system time as Unix epoch milliseconds
  - add getUnixTimestamp() for epoch timestamps in seconds
  - replace chrono wall-clock usage in ecode plugins with Sys APIs
  - update existing Sys time callers for the new millisecond contract
  - remove redundant chrono inclusion from HTTP tests
  - remove the completed user-defined snippets plan

This prevents chrono and std::format internals from being instantiated across large portions of the project while preserving timestamp precision.
This commit is contained in:
Martín Lucas Golini
2026-08-03 00:10:00 -03:00
parent 861b2bc3c4
commit bfe72a439b
12 changed files with 53 additions and 949 deletions
+1 -1
View File
@@ -685,7 +685,7 @@ void TexturePacker::saveTextureRegions() {
TexGrHdr.Magic = EE_TEXTURE_ATLAS_MAGIC;
TexGrHdr.Version = HDR_TEXTURE_ATLAS_VERSION;
TexGrHdr.Date = static_cast<Uint64>( Sys::getSystemTime() );
TexGrHdr.Date = static_cast<Uint64>( Sys::getUnixTimestamp() );
TexGrHdr.TextureCount = 1;
TexGrHdr.Format = static_cast<int>( mFormat );
TexGrHdr.Width = mWidth;
+1 -1
View File
@@ -1815,7 +1815,7 @@ static constexpr const char* LINE_END = "\r\n";
Http::MultipartEntitiesBuilder::MultipartEntitiesBuilder() :
MultipartEntitiesBuilder( "eepp-client-boundary-" +
String::toString( (Uint64)Sys::getSystemTime() ) ) {}
String::toString( Sys::getUnixTimestamp() ) ) {}
Http::MultipartEntitiesBuilder::MultipartEntitiesBuilder( const std::string& boundary ) :
mBoundary( boundary ) {}
+13 -4
View File
@@ -1,7 +1,18 @@
#include <eepp/system/clock.hpp>
#include <chrono>
namespace EE { namespace System {
using ClockImpl = std::conditional_t<std::chrono::high_resolution_clock::is_steady,
std::chrono::high_resolution_clock, std::chrono::steady_clock>;
static Int64 nowMicroseconds() {
return std::chrono::duration_cast<std::chrono::microseconds>(
ClockImpl::now().time_since_epoch() )
.count();
}
Clock::Clock() {
restart();
}
@@ -9,13 +20,11 @@ Clock::Clock() {
Clock::~Clock() {}
void Clock::restart() {
mRefPoint = ClockImpl::now();
mRefPoint = nowMicroseconds();
}
Time Clock::getElapsedTime() const {
return Microseconds(
std::chrono::duration_cast<std::chrono::microseconds>( ClockImpl::now() - mRefPoint )
.count() );
return Microseconds( nowMicroseconds() - mRefPoint );
}
Time Clock::getElapsedTimeAndReset() {
+22 -12
View File
@@ -701,27 +701,37 @@ std::string Sys::getProcessPath() {
return path;
}
double Sys::getSystemTime() {
Int64 Sys::getSystemTime() {
#if EE_PLATFORM == EE_PLATFORM_WIN
static LARGE_INTEGER Frequency;
static BOOL UseHighPerformanceTimer = QueryPerformanceFrequency( &Frequency );
using GetSystemTimePreciseAsFileTimeType = VOID( WINAPI* )( LPFILETIME );
static const auto getSystemTimePreciseAsFileTime =
reinterpret_cast<GetSystemTimePreciseAsFileTimeType>(
GetProcAddress( GetModuleHandleA( "kernel32.dll" ),
"GetSystemTimePreciseAsFileTime" ) );
if ( UseHighPerformanceTimer ) {
// High performance counter available : use it
LARGE_INTEGER CurrentTime;
QueryPerformanceCounter( &CurrentTime );
return static_cast<double>( CurrentTime.QuadPart ) / Frequency.QuadPart;
} else
// High performance counter not available : use GetTickCount (less accurate)
return GetTickCount() * 0.001;
FILETIME fileTime;
if ( getSystemTimePreciseAsFileTime )
getSystemTimePreciseAsFileTime( &fileTime );
else
GetSystemTimeAsFileTime( &fileTime );
ULARGE_INTEGER ticks;
ticks.LowPart = fileTime.dwLowDateTime;
ticks.HighPart = fileTime.dwHighDateTime;
constexpr Int64 WINDOWS_TO_UNIX_EPOCH = 116444736000000000LL;
return ( static_cast<Int64>( ticks.QuadPart ) - WINDOWS_TO_UNIX_EPOCH ) / 10000;
#else
timeval Time = { 0, 0 };
gettimeofday( &Time, NULL );
return Time.tv_sec + Time.tv_usec / 1000000.;
return static_cast<Int64>( Time.tv_sec ) * 1000 + Time.tv_usec / 1000;
#endif
}
Int64 Sys::getUnixTimestamp() {
return getSystemTime() / 1000;
}
ProcessID Sys::getProcessID() {
#if EE_PLATFORM == EE_PLATFORM_WIN
return GetCurrentProcessId();
+1 -1
View File
@@ -165,7 +165,7 @@ void EETest::init() {
Scenes[4] = [this] { screen4(); };
Scenes[5] = [this] { screen5(); };
setRandomSeed( static_cast<Uint32>( Sys::getSystemTime() * 1000 ) );
setRandomSeed( static_cast<Uint32>( Sys::getSystemTime() ) );
loadTextures();
-1
View File
@@ -1,7 +1,6 @@
#include "utest.h"
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <mutex>
#include <thread>
@@ -28,7 +28,6 @@
#include <eepp/window/window.hpp>
#include <eterm/ui/uiterminal.hpp>
#include <chrono>
#include <nlohmann/json.hpp>
using namespace EE::System;
@@ -2326,7 +2325,7 @@ nlohmann::json LLMChatUI::serializeChat( const LLMModel& model, bool forRequest
}
nlohmann::json LLMChatUI::serialize() {
mTimestamp = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() );
mTimestamp = Sys::getUnixTimestamp();
nlohmann::json j;
j["uuid"] = mUUID.toString();
if ( !mIsAgentMode ) {
@@ -3179,7 +3178,7 @@ void LLMChatUI::deleteOldConversations( int days ) {
std::string conversationsPath = plugin->getConversationsPath();
auto history = ChatHistory::getHistory( conversationsPath );
Int64 olderThanTime = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() ) -
Int64 olderThanTime = Sys::getUnixTimestamp() -
( 60 * 60 * 24 * days );
for ( const auto& chat : history )
@@ -15,7 +15,6 @@
#include <algorithm>
#include <array>
#include <chrono>
#include <ctime>
#include <nlohmann/json.hpp>
#include <string_view>
@@ -1126,12 +1125,10 @@ SnippetParser::VariableMap AutoCompletePlugin::snippetVariables( TextDocument& d
FileSystem::dirRemoveSlashAtEnd( workspaceFolder );
std::string workspaceName( FileSystem::fileNameFromPath( workspaceFolder ) );
const auto now = std::chrono::system_clock::now();
const auto nowTime = std::chrono::system_clock::to_time_t( now );
const auto milliseconds = Sys::getSystemTime();
const auto nowTime = static_cast<std::time_t>( Sys::getUnixTimestamp() );
const std::tm* localTimePtr = std::localtime( &nowTime );
const std::tm localTime = localTimePtr ? *localTimePtr : std::tm{};
const auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch() );
std::string timezoneOffset = formatSnippetTime( localTime, "%z" );
if ( timezoneOffset.size() == 5 )
timezoneOffset.insert( 3, ":" );
@@ -1168,11 +1165,11 @@ SnippetParser::VariableMap AutoCompletePlugin::snippetVariables( TextDocument& d
{ "CURRENT_MINUTE", formatSnippetTime( localTime, "%M" ) },
{ "CURRENT_SECOND", formatSnippetTime( localTime, "%S" ) },
{ "CURRENT_MILLISECOND",
String::format( "%03d", static_cast<int>( milliseconds.count() % 1000 ) ) },
String::format( "%03d", static_cast<int>( milliseconds % 1000 ) ) },
{ "CURRENT_SECONDS_UNIX",
String::toString( static_cast<Int64>( milliseconds.count() / 1000 ) ) },
String::toString( static_cast<Int64>( milliseconds / 1000 ) ) },
{ "CURRENT_MILLISECONDS_UNIX",
String::toString( static_cast<Int64>( milliseconds.count() ) ) },
String::toString( static_cast<Int64>( milliseconds ) ) },
{ "CURRENT_TIMEZONE_OFFSET", timezoneOffset },
{ "CURRENT_TIMEZONE_NAME", formatSnippetTime( localTime, "%Z" ) },
{ "RANDOM", String::format( "%06d", Math::randi( 0, 999999 ) ) },
@@ -1218,8 +1218,7 @@ bool DebuggerPlugin::replaceInVal( std::string& val,
String::replaceAll( val, KEY_PATH_SEPARATOR_ABBR, FileSystem::getOSSlash() );
String::replaceAll( val, KEY_UUID, UUID().toString() );
String::replaceAll( val, KEY_TIMESTAMP,
std::to_string( std::chrono::system_clock::to_time_t(
std::chrono::system_clock::now() ) ) );
std::to_string( Sys::getUnixTimestamp() ) );
auto* editor = getPluginContext()->getSplitter()->getCurEditor();
if ( getPluginContext()->getSplitter()->getCurEditor() ) {