Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions benchmarks/io_chunks/canbench_results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,42 @@ benches:
read_chunks_vec_1:
total:
calls: 1
instructions: 104859760
instructions: 104859642
heap_increase: 0
stable_memory_increase: 0
scopes: {}
read_chunks_vec_1k:
total:
calls: 1
instructions: 105826498
instructions: 105511618
heap_increase: 0
stable_memory_increase: 0
scopes: {}
read_chunks_vec_1m:
total:
calls: 1
instructions: 1010905944
instructions: 696002618
heap_increase: 0
stable_memory_increase: 0
scopes: {}
write_chunks_btreemap_1:
total:
calls: 1
instructions: 357205397
instructions: 360207245
heap_increase: 13
stable_memory_increase: 1536
scopes: {}
write_chunks_btreemap_1k:
total:
calls: 1
instructions: 4187119879
instructions: 4194582593
heap_increase: 2
stable_memory_increase: 1536
scopes: {}
write_chunks_btreemap_1m:
total:
calls: 1
instructions: 83659829857
instructions: 83673829307
heap_increase: 0
stable_memory_increase: 3072
scopes: {}
Expand Down Expand Up @@ -107,21 +107,21 @@ benches:
write_chunks_vec_1:
total:
calls: 1
instructions: 549903573
instructions: 549903446
heap_increase: 0
stable_memory_increase: 1536
scopes: {}
write_chunks_vec_1k:
total:
calls: 1
instructions: 562257515
instructions: 562132513
heap_increase: 0
stable_memory_increase: 1536
scopes: {}
write_chunks_vec_1m:
total:
calls: 1
instructions: 1896593101
instructions: 1771593099
heap_increase: 0
stable_memory_increase: 1536
scopes: {}
Expand Down
32 changes: 16 additions & 16 deletions benchmarks/vec/canbench_results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,112 +2,112 @@ benches:
vec_get_blob_128:
total:
calls: 1
instructions: 19246661
instructions: 18706659
heap_increase: 0
stable_memory_increase: 0
scopes: {}
vec_get_blob_16:
total:
calls: 1
instructions: 6405945
instructions: 5897185
heap_increase: 0
stable_memory_increase: 0
scopes: {}
vec_get_blob_32:
total:
calls: 1
instructions: 7123504
instructions: 6654118
heap_increase: 0
stable_memory_increase: 0
scopes: {}
vec_get_blob_4:
total:
calls: 1
instructions: 4824326
instructions: 4284326
heap_increase: 0
stable_memory_increase: 0
scopes: {}
vec_get_blob_4_mem_manager:
total:
calls: 1
instructions: 7191676
instructions: 5891676
heap_increase: 0
stable_memory_increase: 0
scopes: {}
vec_get_blob_64:
total:
calls: 1
instructions: 11310943
instructions: 10751237
heap_increase: 0
stable_memory_increase: 0
scopes: {}
vec_get_blob_64_mem_manager:
total:
calls: 1
instructions: 13651091
instructions: 12331385
heap_increase: 0
stable_memory_increase: 0
scopes: {}
vec_get_blob_8:
total:
calls: 1
instructions: 5723200
instructions: 5213200
heap_increase: 0
stable_memory_increase: 0
scopes: {}
vec_get_u64:
total:
calls: 1
instructions: 4790305
instructions: 3530307
heap_increase: 0
stable_memory_increase: 0
scopes: {}
vec_insert_blob_128:
total:
calls: 1
instructions: 4171424
instructions: 3821424
heap_increase: 0
stable_memory_increase: 19
scopes: {}
vec_insert_blob_16:
total:
calls: 1
instructions: 3336227
instructions: 2986227
heap_increase: 0
stable_memory_increase: 2
scopes: {}
vec_insert_blob_32:
total:
calls: 1
instructions: 3455467
instructions: 3105467
heap_increase: 0
stable_memory_increase: 5
scopes: {}
vec_insert_blob_4:
total:
calls: 1
instructions: 3247468
instructions: 2897468
heap_increase: 0
stable_memory_increase: 0
scopes: {}
vec_insert_blob_64:
total:
calls: 1
instructions: 3695804
instructions: 3345804
heap_increase: 0
stable_memory_increase: 9
scopes: {}
vec_insert_blob_8:
total:
calls: 1
instructions: 3276889
instructions: 2926889
heap_increase: 0
stable_memory_increase: 1
scopes: {}
vec_insert_u64:
total:
calls: 1
instructions: 5379519
instructions: 4999519
heap_increase: 0
stable_memory_increase: 1
scopes: {}
Expand Down
7 changes: 6 additions & 1 deletion src/base_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use crate::{
Memory, Storable,
};
use std::borrow::{Borrow, Cow};
use std::cell::Cell;
use std::cmp::min;
use std::fmt;
use std::marker::PhantomData;
Expand Down Expand Up @@ -95,6 +96,7 @@ impl std::error::Error for InitError {}

pub struct BaseVec<T: Storable, M: Memory> {
memory: M,
cached_len: Cell<u64>,
_marker: PhantomData<T>,
}

Expand All @@ -117,6 +119,7 @@ impl<T: Storable, M: Memory> BaseVec<T, M> {
Self::write_header(&header, &memory)?;
Ok(Self {
memory,
cached_len: Cell::new(0),
_marker: PhantomData,
})
}
Expand Down Expand Up @@ -148,6 +151,7 @@ impl<T: Storable, M: Memory> BaseVec<T, M> {

Ok(Self {
memory,
cached_len: Cell::new(header.len),
_marker: PhantomData,
})
}
Expand Down Expand Up @@ -178,7 +182,7 @@ impl<T: Storable, M: Memory> BaseVec<T, M> {
///
/// Complexity: O(1)
pub fn len(&self) -> u64 {
read_u64(&self.memory, Address::from(LEN_OFFSET))
self.cached_len.get()
}

/// Sets the item at the specified index to the specified value.
Expand Down Expand Up @@ -264,6 +268,7 @@ impl<T: Storable, M: Memory> BaseVec<T, M> {
/// Sets the vector's length.
fn set_len(&self, new_len: u64) {
write_u64(&self.memory, Address::from(LEN_OFFSET), new_len);
self.cached_len.set(new_len);
}

/// Writes the size of the item at the specified offset.
Expand Down
Loading