Skip to content

Commit c9d17d6

Browse files
touch stable structure (dfinity#93)
* touch stable structure * fix * fix
1 parent b300fec commit c9d17d6

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

.github/workflows/diff.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ def read_tables(file):
7676
for col in current.columns:
7777
x = row[col]
7878
base = main.loc[idx, col]
79-
d = (x - base) / base * 100
79+
if base == 0:
80+
d = 0
81+
else:
82+
d = (x - base) / base * 100
8083
if d < 0:
8184
result.loc[idx, col] = f"{x:_} ($\\textcolor{{green}}{{{d:.2f}\\\\%}}$)"
8285
elif d > 0:

collections/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ the same elements, and the queries are exactly the same. Below we explain the me
3030
> + Use stable variable directly in Motoko: `zhenya_hashmap`, `btree`, `vector`
3131
> + Expose and serialize external state (`share/unshare` in Motoko, `candid::Encode` in Rust): `rbtree`, `heap`, `btreemap_rs`, `hashmap_rs`, `heap_rs`, `vector_rs`
3232
> + Use pre/post-upgrade hooks to convert data into an array: `hashmap`, `splay`, `triemap`, `buffer`, `imrc_hashmap_rs`
33-
> * 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.
33+
> * 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.
3434
> * `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.
3535
> * `btree` comes from [mops.one/stableheapbtreemap](https://mops.one/stableheapbtreemap).
3636
> * `zhenya_hashmap` comes from [mops.one/map](https://mops.one/map).

collections/rust/src/btreemap_stable/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ fn init() {
1212
utils::profiling_init();
1313
}
1414

15+
#[ic_cdk::post_upgrade]
16+
fn post_upgrade() {
17+
MAP.with(|map| drop(map.borrow()));
18+
}
19+
1520
#[ic_cdk::update]
1621
fn generate(size: u32) {
1722
let rand = Random::new(Some(size), 1);

collections/rust/src/heap_stable/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ fn init() {
1313
utils::profiling_init();
1414
}
1515

16+
#[ic_cdk::post_upgrade]
17+
fn post_upgrade() {
18+
MAP.with(|map| drop(map.borrow()));
19+
}
20+
1621
#[ic_cdk::update]
1722
fn generate(size: u32) {
1823
let rand = Random::new(Some(size), 1);

collections/rust/src/vector_stable/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ fn init() {
1111
utils::profiling_init();
1212
}
1313

14+
#[ic_cdk::post_upgrade]
15+
fn post_upgrade() {
16+
MAP.with(|map| drop(map.borrow()));
17+
}
18+
1419
#[ic_cdk::update]
1520
fn generate(size: u32) {
1621
MAP.with(|map| {

0 commit comments

Comments
 (0)