Remove slower unit symbol cache

This commit is contained in:
udo
2026-07-16 18:18:39 +00:00
parent ea89e3bb6d
commit ab3e4dac2e
5 changed files with 6 additions and 44 deletions
+4 -35
View File
@@ -125,8 +125,6 @@ struct WasmRequestProfile
u64 unit_import_total_us = 0;
u64 unit_instantiate_total_us = 0;
u64 unit_initialize_total_us = 0;
u64 unit_symbol_lookup_count = 0;
u64 unit_symbol_cache_hit_count = 0;
u64 hostcall_count = 0;
u64 hostcall_total_us = 0;
u64 mysql_hostcall_count = 0;
@@ -1146,8 +1144,6 @@ private:
std::vector<LoadedUnit> units;
std::map<String, size_t> units_by_source;
std::map<String, u32> handler_slots; // source + ":" + symbol → table slot
std::map<String, wasmtime::Func> resolved_funcs;
std::map<String, u32> resolved_data;
std::vector<wasmtime::Func> host_funcs; // keep host imports alive
wasmtime::Store::Context ctx()
@@ -1229,24 +1225,11 @@ private:
std::optional<wasmtime::Func> resolve_func(const String& name)
{
unit_symbol_lookup_count++;
auto cached = resolved_funcs.find(name);
if(cached != resolved_funcs.end())
{
unit_symbol_cache_hit_count++;
return(cached->second);
}
if(auto func = core_func(name))
{
resolved_funcs.emplace(name, *func);
return(func);
}
for(size_t i = 0; i < units.size(); i++)
if(auto func = unit_func(i, name))
{
resolved_funcs.emplace(name, *func);
return(func);
}
return(std::nullopt);
}
@@ -1254,21 +1237,12 @@ private:
// (core is non-PIC → base 0; PIC units export __memory_base-relative)
bool resolve_data(const String& name, u32& address_out)
{
unit_symbol_lookup_count++;
auto cached = resolved_data.find(name);
if(cached != resolved_data.end())
{
unit_symbol_cache_hit_count++;
address_out = cached->second;
return(true);
}
auto from_core = core->get(ctx(), std::string_view(name));
if(from_core)
if(auto* global = std::get_if<wasmtime::Global>(&*from_core))
{
address_out = (u32)global->get(ctx()).i32();
resolved_data[name] = address_out;
return(true);
{
address_out = (u32)global->get(ctx()).i32();
return(true);
}
for(size_t i = 0; i < units.size(); i++)
{
@@ -1277,7 +1251,6 @@ private:
if(auto* global = std::get_if<wasmtime::Global>(&*exported))
{
address_out = units[i].memory_base + (u32)global->get(ctx()).i32();
resolved_data[name] = address_out;
return(true);
}
}
@@ -1459,11 +1432,9 @@ private:
if(!own || !std::get_if<wasmtime::Global>(&*own))
return(source_path + ": GOT.mem." + name + " defined neither by core nor by any unit");
u32 offset = (u32)std::get<wasmtime::Global>(*own).get(cx).i32();
u32 address = memory_base + offset;
auto set = got.set(cx, wasmtime::Val((int32_t)address));
auto set = got.set(cx, wasmtime::Val((int32_t)(memory_base + offset)));
if(!set)
return("GOT patch failed: " + String(set.err().message()));
resolved_data[name] = address;
}
// init sequence, then bind this unit's context to the request
@@ -1946,8 +1917,6 @@ private:
response["unit_import_us"] = (f64)self->unit_import_total_us;
response["unit_instantiate_us"] = (f64)self->unit_instantiate_total_us;
response["unit_initialize_us"] = (f64)self->unit_initialize_total_us;
response["unit_symbol_lookups"] = (f64)self->unit_symbol_lookup_count;
response["unit_symbol_cache_hits"] = (f64)self->unit_symbol_cache_hit_count;
f64 running_us = response["running_us"].to_f64();
f64 accounted_us = (f64)(self->dispatch_us + self->workspace_setup_us + self->workspace_birth_us + self->context_apply_us + self->hostcall_total_us);
response["guest_us"] = running_us > accounted_us ? running_us - accounted_us : 0.0;