Profile pre-dispatch WASM readiness

This commit is contained in:
udo
2026-07-18 05:43:36 +00:00
parent a5ad5042b7
commit 556025a779
6 changed files with 58 additions and 3 deletions
+13 -1
View File
@@ -116,17 +116,26 @@ static bool wasm_artifact_exists(Request* context, const String& entry_unit)
return(false);
String wasm_path = context->server->config["BIN_DIRECTORY"] + entry_unit + ".wasm";
struct stat wasm_st;
f64 phase_started = time_precise();
context->stats.wasm_ready_check_count++;
if(stat(wasm_path.c_str(), &wasm_st) != 0 || !S_ISREG(wasm_st.st_mode))
{
context->stats.wasm_ready_artifact_stat_us += (u64)((time_precise() - phase_started) * 1000000.0);
return(false);
}
context->stats.wasm_ready_artifact_stat_us += (u64)((time_precise() - phase_started) * 1000000.0);
// Require the artifact to satisfy the full compiler freshness check. Source
// mtime alone misses runtime/unit ABI changes, setup-template changes, and
// metadata mismatches, which can leave stale wasm with old imports.
bool source_missing = false;
phase_started = time_precise();
if(compiler_unit_needs_recompile(context, entry_unit, &source_missing))
{
context->stats.wasm_ready_freshness_us += (u64)((time_precise() - phase_started) * 1000000.0);
compiler_prioritize_unit(context, entry_unit);
return(compiler_request_can_serve_stale_artifact(context));
}
context->stats.wasm_ready_freshness_us += (u64)((time_precise() - phase_started) * 1000000.0);
if(source_missing)
return(false);
return(true);
@@ -141,7 +150,10 @@ bool wasm_backend_should_handle(Request& request, const String& entry_unit)
return(false);
if(!wasm_artifact_exists(&request, entry_unit))
return(false);
if(wasm_backend_ensure_started(&request) != "")
f64 phase_started = time_precise();
String start_error = wasm_backend_ensure_started(&request);
request.stats.wasm_ready_worker_us += (u64)((time_precise() - phase_started) * 1000000.0);
if(start_error != "")
return(false);
return(true);
}