Skip to content

Commit

Permalink
touch stable structure (#93)
Browse files Browse the repository at this point in the history
* touch stable structure

* fix

* fix
  • Loading branch information
chenyan-dfinity authored Oct 3, 2023
1 parent b300fec commit c9d17d6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion collections/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
5 changes: 5 additions & 0 deletions collections/rust/src/btreemap_stable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions collections/rust/src/heap_stable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions collections/rust/src/vector_stable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down

0 comments on commit c9d17d6

Please sign in to comment.