Precompile native modules off request path

This commit is contained in:
udo
2026-07-16 22:51:16 +00:00
parent a247c2b520
commit 8dd307d316
6 changed files with 84 additions and 8 deletions
+30
View File
@@ -1049,6 +1049,36 @@ public:
return(unit);
}
static bool serialized_module_needs_refresh(const String& wasm_path)
{
struct stat wasm_stat;
struct stat cached_stat;
String cached_path = cached_wasm_path(wasm_path);
if(stat(wasm_path.c_str(), &wasm_stat) != 0)
return(false);
if(stat(cached_path.c_str(), &cached_stat) != 0)
return(true);
return(cached_stat.st_mtim.tv_sec < wasm_stat.st_mtim.tv_sec ||
(cached_stat.st_mtim.tv_sec == wasm_stat.st_mtim.tv_sec && cached_stat.st_mtim.tv_nsec <= wasm_stat.st_mtim.tv_nsec));
}
static String serialize_module_artifact(const String& wasm_path)
{
if(!serialized_module_needs_refresh(wasm_path))
return("");
std::vector<u8> bytes;
if(!wasm_read_file(wasm_path, bytes))
return("cannot read " + wasm_path);
wasmtime::Engine engine = make_engine();
String error;
auto module = compile_and_cache_module(engine, cached_wasm_path(wasm_path), bytes, error);
if(!module)
return(error);
if(serialized_module_needs_refresh(wasm_path))
return("cannot publish serialized module for " + wasm_path);
return("");
}
private:
static String cached_wasm_path(const String& wasm_path)
{