Skip to content

Commit

Permalink
precompute offsets ahead-of-time rather than on each dereference
Browse files Browse the repository at this point in the history
Criterion results on a test related to nearcore-private-1#2:
compile                 time:   [9.7873 ms 9.8477 ms 9.9119 ms]
                        change: [-5.2388% -4.2981% -3.2369%] (p = 0.00 < 0.05)
                        Performance has improved.

Manual testing on the exact test of nearcore-private-1#2 confirms the ~5% speedup:

Non-rayon goes down to 24.5-25ms from 25.5-26ms
Rayon goes down to 12ms from 12.5ms
  • Loading branch information
Ekleog-NEAR committed Sep 22, 2022
1 parent 54438eb commit f992fcf
Show file tree
Hide file tree
Showing 2 changed files with 206 additions and 196 deletions.
4 changes: 2 additions & 2 deletions lib/vm/src/instance/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl InstanceAllocator {
/// memory, i.e. `Self.instance_ptr` must have been allocated by
/// `Self::new`.
unsafe fn memory_definition_locations(&self) -> Vec<NonNull<VMMemoryDefinition>> {
let num_memories = self.offsets.num_local_memories;
let num_memories = self.offsets.num_local_memories();
let num_memories = usize::try_from(num_memories).unwrap();
let mut out = Vec::with_capacity(num_memories);

Expand Down Expand Up @@ -163,7 +163,7 @@ impl InstanceAllocator {
/// memory, i.e. `Self.instance_ptr` must have been allocated by
/// `Self::new`.
unsafe fn table_definition_locations(&self) -> Vec<NonNull<VMTableDefinition>> {
let num_tables = self.offsets.num_local_tables;
let num_tables = self.offsets.num_local_tables();
let num_tables = usize::try_from(num_tables).unwrap();
let mut out = Vec::with_capacity(num_tables);

Expand Down
Loading

0 comments on commit f992fcf

Please sign in to comment.