Cache read component path resolutions
This commit is contained in:
+33
-3
@@ -1167,7 +1167,13 @@ private:
|
||||
bool stale = false;
|
||||
String source_generation;
|
||||
};
|
||||
struct ComponentResolutionState
|
||||
{
|
||||
std::chrono::steady_clock::time_point checked_at;
|
||||
String resolved;
|
||||
};
|
||||
std::map<String, ComponentFreshnessState> component_freshness;
|
||||
std::map<String, ComponentResolutionState> component_resolutions;
|
||||
|
||||
static String cached_wasm_path(const String& wasm_path)
|
||||
{
|
||||
@@ -2412,6 +2418,9 @@ private:
|
||||
String error;
|
||||
size_t unit_index = 0;
|
||||
bool loaded_reuse = false;
|
||||
String method = context ? to_upper(trim(context->params["REQUEST_METHOD"])) : String("");
|
||||
bool cacheable_read = method == "GET" || method == "HEAD";
|
||||
bool read_request = cacheable_read || method == "OPTIONS";
|
||||
auto loaded = units_by_source.find(file_name);
|
||||
if(loaded == units_by_source.end())
|
||||
{
|
||||
@@ -2427,7 +2436,30 @@ private:
|
||||
component_loaded_reuse_count++;
|
||||
}
|
||||
else
|
||||
resolved = resolve_source_path(file_name, current_unit);
|
||||
{
|
||||
String cache_key = entry_dir + "\t" + resolve_key;
|
||||
auto cached = worker.component_resolutions.find(cache_key);
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
if(cacheable_read && cached != worker.component_resolutions.end() &&
|
||||
std::chrono::duration_cast<std::chrono::seconds>(now - cached->second.checked_at).count() < 10)
|
||||
resolved = cached->second.resolved;
|
||||
else
|
||||
{
|
||||
resolved = resolve_source_path(file_name, current_unit);
|
||||
if(cacheable_read && resolved != "")
|
||||
{
|
||||
if(cached == worker.component_resolutions.end() && worker.component_resolutions.size() >= 4096)
|
||||
{
|
||||
auto oldest = worker.component_resolutions.begin();
|
||||
for(auto it = worker.component_resolutions.begin(); it != worker.component_resolutions.end(); ++it)
|
||||
if(it->second.checked_at < oldest->second.checked_at)
|
||||
oldest = it;
|
||||
worker.component_resolutions.erase(oldest);
|
||||
}
|
||||
worker.component_resolutions[cache_key] = { now, resolved };
|
||||
}
|
||||
}
|
||||
}
|
||||
component_path_total_us += (u64)std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - probe_start).count();
|
||||
if(resolved == "")
|
||||
@@ -2447,8 +2479,6 @@ private:
|
||||
auto artifact_start = std::chrono::steady_clock::now();
|
||||
bool artifact_exists = file_exists_host(worker.unit_wasm_path(resolved));
|
||||
bool can_serve_stale = compiler_request_can_serve_stale_artifact(context);
|
||||
String method = context ? to_upper(trim(context->params["REQUEST_METHOD"])) : String("");
|
||||
bool read_request = method == "GET" || method == "HEAD" || method == "OPTIONS";
|
||||
if(can_serve_stale && read_request && !component_source_generation_checked)
|
||||
{
|
||||
component_source_generation = compiler_source_generation(context);
|
||||
|
||||
Reference in New Issue
Block a user