diff --git a/.github/workflows/diff.py b/.github/workflows/diff.py index f021d577..ae3408e9 100644 --- a/.github/workflows/diff.py +++ b/.github/workflows/diff.py @@ -76,7 +76,10 @@ def read_tables(file): for col in current.columns: x = row[col] base = main.loc[idx, col] - d = (x - base) / base * 100 + if base == 0: + d = 0 + else: + d = (x - base) / base * 100 if d < 0: result.loc[idx, col] = f"{x:_} ($\\textcolor{{green}}{{{d:.2f}\\\\%}}$)" elif d > 0: diff --git a/collections/README.md b/collections/README.md index 588e6dbe..32269267 100644 --- a/collections/README.md +++ b/collections/README.md @@ -30,7 +30,7 @@ the same elements, and the queries are exactly the same. Below we explain the me > + Use stable variable directly in Motoko: `zhenya_hashmap`, `btree`, `vector` > + Expose and serialize external state (`share/unshare` in Motoko, `candid::Encode` in Rust): `rbtree`, `heap`, `btreemap_rs`, `hashmap_rs`, `heap_rs`, `vector_rs` > + Use pre/post-upgrade hooks to convert data into an array: `hashmap`, `splay`, `triemap`, `buffer`, `imrc_hashmap_rs` -> * The stable benchmarks are much more expensive than their non-stable counterpart, because the stable memory API is much more expensive. The benefit is that they get zero cost upgrade. +> * The stable benchmarks are much more expensive than their non-stable counterpart, because the stable memory API is much more expensive. The benefit is that they get fast upgrade. The upgrade still needs to parse the metadata when initializing the upgraded Wasm module. > * `hashmap` uses amortized data structure. When the initial capacity is reached, it has to copy the whole array, thus the cost of `batch_put 50` is much higher than other data structures. > * `btree` comes from [mops.one/stableheapbtreemap](https://mops.one/stableheapbtreemap). > * `zhenya_hashmap` comes from [mops.one/map](https://mops.one/map). diff --git a/collections/rust/src/btreemap_stable/src/lib.rs b/collections/rust/src/btreemap_stable/src/lib.rs index de530f3f..f107678d 100644 --- a/collections/rust/src/btreemap_stable/src/lib.rs +++ b/collections/rust/src/btreemap_stable/src/lib.rs @@ -12,6 +12,11 @@ fn init() { utils::profiling_init(); } +#[ic_cdk::post_upgrade] +fn post_upgrade() { + MAP.with(|map| drop(map.borrow())); +} + #[ic_cdk::update] fn generate(size: u32) { let rand = Random::new(Some(size), 1); diff --git a/collections/rust/src/heap_stable/src/lib.rs b/collections/rust/src/heap_stable/src/lib.rs index 050dbefb..e63e1420 100644 --- a/collections/rust/src/heap_stable/src/lib.rs +++ b/collections/rust/src/heap_stable/src/lib.rs @@ -13,6 +13,11 @@ fn init() { utils::profiling_init(); } +#[ic_cdk::post_upgrade] +fn post_upgrade() { + MAP.with(|map| drop(map.borrow())); +} + #[ic_cdk::update] fn generate(size: u32) { let rand = Random::new(Some(size), 1); diff --git a/collections/rust/src/vector_stable/src/lib.rs b/collections/rust/src/vector_stable/src/lib.rs index 32e8e2ba..e5ca1e1d 100644 --- a/collections/rust/src/vector_stable/src/lib.rs +++ b/collections/rust/src/vector_stable/src/lib.rs @@ -11,6 +11,11 @@ fn init() { utils::profiling_init(); } +#[ic_cdk::post_upgrade] +fn post_upgrade() { + MAP.with(|map| drop(map.borrow())); +} + #[ic_cdk::update] fn generate(size: u32) { MAP.with(|map| {