You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: collections/README.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@
2
2
3
3
Measure different collection libraries written in both Motoko and Rust.
4
4
The library names with `_rs` suffix are written in Rust; the rest are written in Motoko.
5
+
The `_stable` and `_stable_rs` suffix represents that the library directly writes the state to stable memory using `Region` in Motoko and `ic-stable-stuctures` in Rust.
5
6
6
7
We use the same random number generator with fixed seed to ensure that all collections contain
7
8
the same elements, and the queries are exactly the same. Below we explain the measurements of each column in the table:
@@ -11,7 +12,7 @@ the same elements, and the queries are exactly the same. Below we explain the me
11
12
* batch_get 50. Find 50 elements from the collection.
12
13
* batch_put 50. Insert 50 elements to the collection.
13
14
* batch_remove 50. Remove 50 elements from the collection.
14
-
* upgrade. Upgrade the canister with the same Wasm module. The map state is persisted by serializing and deserializing states into stable memory.
15
+
* upgrade. Upgrade the canister with the same Wasm module. For non-stable benchmarks, the map state is persisted by serializing and deserializing states into stable memory. For stable benchmarks, the upgrade takes no cycles, as the state is already in the stable memory.
15
16
16
17
## **💎 Takeaways**
17
18
@@ -29,6 +30,7 @@ the same elements, and the queries are exactly the same. Below we explain the me
29
30
> + Use stable variable directly in Motoko: `zhenya_hashmap`, `btree`, `vector`
30
31
> + Expose and serialize external state (`share/unshare` in Motoko, `candid::Encode` in Rust): `rbtree`, `heap`, `btreemap_rs`, `hashmap_rs`, `heap_rs`, `vector_rs`
31
32
> + 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.
32
34
> *`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.
33
35
> *`btree` comes from [mops.one/stableheapbtreemap](https://mops.one/stableheapbtreemap).
34
36
> *`zhenya_hashmap` comes from [mops.one/map](https://mops.one/map).
0 commit comments