Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'abk/run-522-stable-btreemap-benchmark-in-embedders' int…
…o 'master' RUN-522: Stable btreemap benchmark Introduce a benchmark that tests the execution time of an update message which is mutating keys in a `StableBTreeMap`. This benchmark will be expanded in follow-up MRs and used to compare the performance of stable memory with and without Wasm-native stable memory. See merge request dfinity-lab/public/ic!10298
- Loading branch information
Showing
11 changed files
with
158 additions
and
4 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use candid::Encode; | ||
use criterion::Criterion; | ||
|
||
use ic_state_machine_tests::{Cycles, StateMachine}; | ||
use ic_types::ingress::WasmResult; | ||
|
||
const INITIAL_NUMBER_OF_ENTRIES: u64 = 100_000; | ||
const UPDATE_COUNT: u64 = 10_000; | ||
|
||
fn main() { | ||
let env = StateMachine::new(); | ||
let wasm = canister_test::Project::cargo_bin_maybe_from_env("stable_structures_canister", &[]); | ||
|
||
let canister_id = env | ||
.install_canister_with_cycles( | ||
wasm.bytes(), | ||
Encode!(&INITIAL_NUMBER_OF_ENTRIES).unwrap(), | ||
None, | ||
Cycles::new(1 << 64), | ||
) | ||
.unwrap(); | ||
|
||
let mut criterion = Criterion::default().sample_size(10); | ||
let mut group = criterion.benchmark_group("btree"); | ||
group.bench_function("update", |bench| { | ||
bench.iter(|| { | ||
let result = env | ||
.execute_ingress( | ||
canister_id, | ||
"update_increment_values", | ||
Encode!(&UPDATE_COUNT).unwrap(), | ||
) | ||
.unwrap(); | ||
assert!(matches!(result, WasmResult::Reply(_))) | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("//bazel:canisters.bzl", "rust_canister") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
rust_canister( | ||
name = "stable_structures_canister", | ||
srcs = ["src/main.rs"], | ||
proc_macro_deps = ["@crate_index//:ic-cdk-macros"], | ||
service_file = ":stable_structures.did", | ||
deps = [ | ||
"@crate_index//:candid", | ||
"@crate_index//:ic-cdk", | ||
"@crate_index//:ic-stable-structures", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "stable_structures" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
candid = "0.8.1" | ||
ic-cdk = "0.6.0" | ||
ic-cdk-macros = "0.6.0" | ||
ic-stable-structures = "0.5.0" | ||
serde = "1.0.136" | ||
|
||
[[bin]] | ||
name = "stable_structures" | ||
path = "src/main.rs" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Stable Structures Canister | ||
|
||
The purpose of this canister is to provide simple examples of uses of | ||
`ic-stable-structures` in order to benchmark the performance of stable memory | ||
under realistic workloads. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::{cell::RefCell, ops::Range}; | ||
|
||
use ic_stable_structures::{DefaultMemoryImpl, StableBTreeMap}; | ||
|
||
thread_local! { | ||
pub static STABLE_MAP: RefCell<StableBTreeMap<u64, u64, DefaultMemoryImpl>> = RefCell::new( | ||
StableBTreeMap::init( DefaultMemoryImpl::default()) | ||
); | ||
} | ||
|
||
fn increment_values(range: Range<u64>) { | ||
STABLE_MAP.with(|map| { | ||
let mut map = map.borrow_mut(); | ||
for i in range { | ||
match map.get(&i) { | ||
None => map.insert(i, i), | ||
Some(current) => map.insert(i, current + 1), | ||
} | ||
.expect("Error inserting into stable map"); | ||
} | ||
}) | ||
} | ||
|
||
#[ic_cdk_macros::update] | ||
fn update_increment_values(entries_to_update: u64) { | ||
increment_values(0..entries_to_update) | ||
} | ||
|
||
#[ic_cdk_macros::init] | ||
fn init(initial_entry_count: u64) { | ||
increment_values(0..initial_entry_count) | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
service : {} |