Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add fuzz test for memory manager on stable structures #165

Closed
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
19 changes: 19 additions & 0 deletions benchmark-canisters/src/memory_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use ic_stable_structures::{DefaultMemoryImpl, Memory};
const WASM_PAGE_SIZE: usize = 65536;
const MB: usize = 1024 * 1024;
const MB_IN_PAGES: usize = MB / WASM_PAGE_SIZE;
const BUCKET_SIZE_IN_PAGES: u64 = 128;

/// Benchmarks accessing stable memory without using a `MemoryManager` to establish a baseline.
#[ic_cdk_macros::query]
Expand Down Expand Up @@ -56,3 +57,21 @@ pub fn memory_manager_overhead() -> BenchResult {
}
})
}

/// Benchmarks the `MemoryManager` by allocating a large number of buckets.
#[ic_cdk_macros::query]
pub fn memory_manager_buckets_allocation() -> BenchResult {
let mem_mgr = MemoryManager::init(DefaultMemoryImpl::default());

let num_memories = 5;
let buckets_per_memory = 200;

crate::benchmark(|| {
for i in 0..num_memories {
let memory = mem_mgr.get(MemoryId::new(i));
for _ in 0..buckets_per_memory {
memory.grow(BUCKET_SIZE_IN_PAGES);
}
}
})
}
1 change: 1 addition & 0 deletions benchmarks/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ lazy_static::lazy_static! {
// MemoryManager benchmarks
"memory_manager_baseline",
"memory_manager_overhead",
"memory_manager_buckets_allocation",

// BTree benchmarks
"btreemap_insert_10mib_values",
Expand Down
Loading