Precompute fields in VMOffsets

This commit updates the implementation of `VMOffsets` to frontload all
checked arithmetic on construction of the `VMOffsets` which allows
eliding all checked arithmetic when accessing the fields of `VMOffsets`.
For testing and such this adds a new constructor as well from a new
`VMOffsetsFields` structure which is a clone of the old definition.

This should help speed up some profile hot spots I've been seeing where
with all the checked arithmetic on field sizes this was slowing down the
various accessors during instantiation (which uses `VMOffsets` to
initialize various fields of the `VMContext`).
This commit is contained in:
Alex Crichton
2021-04-08 11:28:35 -07:00
parent 8e495ac79d
commit c91e14d83f
4 changed files with 221 additions and 199 deletions

View File

@@ -1166,7 +1166,7 @@ mod tests {
let actual_offset = (next_ptr as usize) - (table_ptr as usize);
let offsets = wasmtime_environ::VMOffsets {
let offsets = wasmtime_environ::VMOffsets::from(wasmtime_environ::VMOffsetsFields {
pointer_size: 8,
num_signature_ids: 0,
num_imported_functions: 0,
@@ -1177,7 +1177,7 @@ mod tests {
num_defined_tables: 0,
num_defined_memories: 0,
num_defined_globals: 0,
};
});
assert_eq!(
offsets.vm_extern_ref_activation_table_next() as usize,
actual_offset
@@ -1193,7 +1193,7 @@ mod tests {
let actual_offset = (end_ptr as usize) - (table_ptr as usize);
let offsets = wasmtime_environ::VMOffsets {
let offsets = wasmtime_environ::VMOffsets::from(wasmtime_environ::VMOffsetsFields {
pointer_size: 8,
num_signature_ids: 0,
num_imported_functions: 0,
@@ -1204,7 +1204,7 @@ mod tests {
num_defined_tables: 0,
num_defined_memories: 0,
num_defined_globals: 0,
};
});
assert_eq!(
offsets.vm_extern_ref_activation_table_end() as usize,
actual_offset