Move function names out of Module (#3789)

* Move function names out of `Module`

This commit moves function names in a module out of the
`wasmtime_environ::Module` type and into separate sections stored in the
final compiled artifact. Spurred on by #3787 to look at module load
times I noticed that a huge amount of time was spent in deserializing
this map. The `spidermonkey.wasm` file, for example, has a 3MB name
section which is a lot of unnecessary data to deserialize at module load
time.

The names of functions are now split out into their own dedicated
section of the compiled artifact and metadata about them is stored in a
more compact format at runtime by avoiding a `BTreeMap` and instead
using a sorted array. Overall this improves deserialize times by up to
80% for modules with large name sections since the name section is no
longer deserialized at load time and it's lazily paged in as names are
actually referenced.

* Fix a typo

* Fix compiled module determinism

Need to not only sort afterwards but also first to ensure the data of
the name section is consistent.
This commit is contained in:
Alex Crichton
2022-02-10 14:34:48 -06:00
committed by GitHub
parent 41eb225765
commit 520a7f26d7
8 changed files with 109 additions and 33 deletions

View File

@@ -13,7 +13,7 @@ use std::path::PathBuf;
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
use wasmparser::Type as WasmType;
use wasmtime_environ::{
DebugInfoData, DefinedFuncIndex, EntityRef, FunctionMetadata, WasmFileInfo,
DebugInfoData, DefinedFuncIndex, EntityRef, FuncIndex, FunctionMetadata, WasmFileInfo,
};
const PRODUCER_NAME: &str = "wasmtime";
@@ -369,7 +369,7 @@ pub fn generate_simulated_dwarf(
let func_index = imported_func_count + (index as u32);
let id = match func_names
.get(&func_index)
.get(&FuncIndex::from_u32(func_index))
.and_then(|s| check_invalid_chars_in_name(s))
{
Some(n) => out_strings.add(assert_dwarf_str!(n)),
@@ -400,7 +400,7 @@ pub fn generate_simulated_dwarf(
&[(source_range.0, source_range.1)],
&wasm_types,
&di.wasm_file.funcs[index],
locals_names.get(&(index as u32)),
locals_names.get(&FuncIndex::from_u32(index as u32)),
out_strings,
isa,
)?;