From 914cf17f23774e604bd8f31949ce379f3108ba4b Mon Sep 17 00:00:00 2001 From: udo Date: Fri, 17 Jul 2026 22:06:17 +0000 Subject: [PATCH] Skip canonicalization for recent source entries --- src/lib/compiler.cpp | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/lib/compiler.cpp b/src/lib/compiler.cpp index 8f41199..2b99d10 100644 --- a/src/lib/compiler.cpp +++ b/src/lib/compiler.cpp @@ -64,6 +64,18 @@ const u64 UCE_UNIT_SOURCE_SIGNATURE_CACHE_MAX = 4096; std::mutex unit_source_signature_cache_mutex; std::map unit_source_signature_cache; +bool compiler_recent_unit_source_entry(String file_name, UnitSourceSignatureEntry& entry) +{ + auto checked_at = std::chrono::steady_clock::now(); + std::lock_guard lock(unit_source_signature_cache_mutex); + auto cached = unit_source_signature_cache.find(file_name); + if(cached == unit_source_signature_cache.end() || + std::chrono::duration_cast(checked_at - cached->second.checked_at).count() >= 1000) + return(false); + entry = cached->second; + return(true); +} + bool compiler_jit_compile_on_request_enabled(Request* context) { if(!context || !context->server) @@ -151,11 +163,9 @@ UnitSourceSignatureEntry compiler_unit_source_entry(String file_name, bool allow auto checked_at = std::chrono::steady_clock::now(); if(allow_recent_stat) { - std::lock_guard lock(unit_source_signature_cache_mutex); - auto cached = unit_source_signature_cache.find(file_name); - if(cached != unit_source_signature_cache.end() && - std::chrono::duration_cast(checked_at - cached->second.checked_at).count() < 1000) - return(cached->second); + UnitSourceSignatureEntry cached; + if(compiler_recent_unit_source_entry(file_name, cached)) + return(cached); } struct stat info; UnitSourceSignatureEntry entry; @@ -189,14 +199,21 @@ UnitSourceSignatureEntry compiler_unit_source_entry(String file_name, bool allow void compiler_append_unit_source_signature(String file_name, std::set& visited, String& signature, bool allow_recent_stat) { - String normalized = path_real(file_name); - if(normalized == "") - normalized = file_name; + String normalized = file_name; + UnitSourceSignatureEntry entry; + bool recent = allow_recent_stat && compiler_recent_unit_source_entry(normalized, entry); + if(!recent) + { + normalized = path_real(file_name); + if(normalized == "") + normalized = file_name; + } if(visited.find(normalized) != visited.end()) return; visited.insert(normalized); - UnitSourceSignatureEntry entry = compiler_unit_source_entry(normalized, allow_recent_stat); + if(!recent) + entry = compiler_unit_source_entry(normalized, allow_recent_stat); signature += normalized + ":" + entry.content_hash + (entry.readable ? String("") : String(":unreadable")) + "\n"; for(String loaded : entry.loaded_paths) compiler_append_unit_source_signature(loaded, visited, signature, allow_recent_stat);