Shrink the size of the anyfunc table in VMContext (#3850)
* Shrink the size of the anyfunc table in `VMContext` This commit shrinks the size of the `VMCallerCheckedAnyfunc` table allocated into a `VMContext` to be the size of the number of "escaped" functions in a module rather than the number of functions in a module. Escaped functions include exports, table elements, etc, and are typically an order of magnitude smaller than the number of functions in general. This should greatly shrink the `VMContext` for some modules which while we aren't necessarily having any problems with that today shouldn't cause any problems in the future. The original motivation for this was that this came up during the recent lazy-table-initialization work and while it no longer has a direct performance benefit since tables aren't initialized at all on instantiation it should still improve long-running instances theoretically with smaller `VMContext` allocations as well as better locality between anyfuncs. * Fix some tests * Remove redundant hash set * Use a helper for pushing function type information * Use a more descriptive `is_escaping` method * Clarify a comment * Fix condition
This commit is contained in:
@@ -256,12 +256,13 @@ fn func_signature(
|
||||
types: &TypeTables,
|
||||
index: FuncIndex,
|
||||
) -> ir::Signature {
|
||||
let func = &translation.module.functions[index];
|
||||
let call_conv = match translation.module.defined_func_index(index) {
|
||||
// If this is a defined function in the module and it's never possibly
|
||||
// exported, then we can optimize this function to use the fastest
|
||||
// calling convention since it's purely an internal implementation
|
||||
// detail of the module itself.
|
||||
Some(idx) if !translation.escaped_funcs.contains(&idx) => CallConv::Fast,
|
||||
// If this is a defined function in the module and it doesn't escape
|
||||
// then we can optimize this function to use the fastest calling
|
||||
// convention since it's purely an internal implementation detail of
|
||||
// the module itself.
|
||||
Some(_idx) if !func.is_escaping() => CallConv::Fast,
|
||||
|
||||
// ... otherwise if it's an imported function or if it's a possibly
|
||||
// exported function then we use the default ABI wasmtime would
|
||||
@@ -269,11 +270,7 @@ fn func_signature(
|
||||
_ => wasmtime_call_conv(isa),
|
||||
};
|
||||
let mut sig = blank_sig(isa, call_conv);
|
||||
push_types(
|
||||
isa,
|
||||
&mut sig,
|
||||
&types.wasm_signatures[translation.module.functions[index]],
|
||||
);
|
||||
push_types(isa, &mut sig, &types.wasm_signatures[func.signature]);
|
||||
return sig;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user