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
+7-1Lines changed: 7 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,7 @@ the same elements, and the queries are exactly the same. Below we explain the me
11
11
* batch_get 50. Find 50 elements from the collection.
12
12
* batch_put 50. Insert 50 elements to the collection.
13
13
* 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.
14
15
15
16
## **💎 Takeaways**
16
17
@@ -22,7 +23,12 @@ the same elements, and the queries are exactly the same. Below we explain the me
22
23
> **Note**
23
24
>
24
25
> * The Candid interface of the benchmark is minimal, therefore the serialization cost is negligible in this measurement.
25
-
> * Due to the instrumentation overhead and cycle limit, we cannot profile computations with large collections. Hopefully, when deterministic time slicing is ready, we can measure the performance on larger memory footprint.
26
+
> * Due to the instrumentation overhead and cycle limit, we cannot profile computations with very large collections.
27
+
> * The `upgrade` column uses Candid for serializing stable data. In Rust, you may get better cycle cost by using a different serialization format. Another slowdown in Rust is that `ic-stable-structures` tends to be slower than the region memory in Motoko.
28
+
> * Different library has different ways for persisting data during upgrades, there are mainly three categories:
29
+
> + Use stable variable directly in Motoko: `zhenya_hashmap`, `btree`, `vector`
30
+
> + Expose and serialize external state (`share/unshare` in Motoko, `candid::Encode` in Rust): `rbtree`, `heap`, `btreemap_rs`, `hashmap_rs`, `heap_rs`, `vector_rs`
31
+
> + Use pre/post-upgrade hooks to convert data into an array: `hashmap`, `splay`, `triemap`, `buffer`, `imrc_hashmap_rs`
26
32
> *`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.
27
33
> *`btree` comes from [mops.one/stableheapbtreemap](https://mops.one/stableheapbtreemap).
28
34
> *`zhenya_hashmap` comes from [mops.one/map](https://mops.one/map).
0 commit comments