Move trap information to a section of the compiled image (#3241)
This commit moves the `traps` field of `FunctionInfo` into a section of the compiled artifact produced by Cranelift. This section is quite large and when previously encoded/decoded with `bincode` this can take quite some time to process. Traps are expected to be relatively rare and it's not necessarily the right tradeoff to spend so much time serializing/deserializing this data, so this commit offloads the section into a custom-encoded binary format located elsewhere in the compiled image. This is similar to #3240 in its goal which is to move very large pieces of metadata to their own sections to avoid decoding anything when we load a precompiled modules. This also has a small benefit that it's slightly more efficient storage for the trap information too, but that's a negligible benefit. This is part of #3230 to make loading modules fast.
This commit is contained in:
@@ -28,7 +28,7 @@ use std::sync::Mutex;
|
||||
use wasmtime_environ::{
|
||||
AddressMapSection, CompileError, FilePos, FlagValue, FunctionBodyData, FunctionInfo,
|
||||
InstructionAddressMap, Module, ModuleTranslation, StackMapInformation, TrapCode,
|
||||
TrapInformation, Tunables, TypeTables, VMOffsets,
|
||||
TrapEncodingBuilder, TrapInformation, Tunables, TypeTables, VMOffsets,
|
||||
};
|
||||
|
||||
/// A compiler that compiles a WebAssembly module with Compiler, translating
|
||||
@@ -208,8 +208,8 @@ impl wasmtime_environ::Compiler for Compiler {
|
||||
value_labels_ranges: ranges.unwrap_or(Default::default()),
|
||||
stack_slots: context.func.stack_slots,
|
||||
unwind_info,
|
||||
traps: trap_sink.traps,
|
||||
info: FunctionInfo {
|
||||
traps: trap_sink.traps,
|
||||
start_srcloc: address_transform.start_srcloc,
|
||||
stack_maps: stack_map_sink.finish(),
|
||||
},
|
||||
@@ -249,10 +249,12 @@ impl wasmtime_environ::Compiler for Compiler {
|
||||
|
||||
let mut builder = ObjectBuilder::new(obj, &translation.module);
|
||||
let mut addrs = AddressMapSection::default();
|
||||
let mut traps = TrapEncodingBuilder::default();
|
||||
|
||||
for (i, func) in funcs.iter() {
|
||||
let range = builder.func(i, func);
|
||||
addrs.push(range, &func.address_map.instructions);
|
||||
addrs.push(range.clone(), &func.address_map.instructions);
|
||||
traps.push(range, &func.traps);
|
||||
}
|
||||
for (i, func) in trampolines.iter() {
|
||||
builder.trampoline(*i, func);
|
||||
@@ -291,6 +293,7 @@ impl wasmtime_environ::Compiler for Compiler {
|
||||
|
||||
builder.finish(&*self.isa)?;
|
||||
addrs.append_to(obj);
|
||||
traps.append_to(obj);
|
||||
|
||||
Ok(funcs.into_iter().map(|(_, f)| f.info).collect())
|
||||
}
|
||||
@@ -533,6 +536,7 @@ impl Compiler {
|
||||
value_labels_ranges: Default::default(),
|
||||
info: Default::default(),
|
||||
address_map: Default::default(),
|
||||
traps: Vec::new(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user