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

touch stable structure #93

Merged
merged 3 commits into from
Oct 3, 2023
Merged
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
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
Loading