Increased Canister Smart Contract Memory

The reason Motoko’s ExperimentalStableMemory library is still marked experimental is that we don’t really like it as a long term solution since it is rather low-level, hard to use, expensive and non-modular. A library is free to access it and can thus mess with any other libraries use of stable memory. It’s like a big global variable that everyone in the program has access to and thus goes against the grain of Motoko’s focus on safety.

A better design would be for the main actor to selectively hand out handles to isolated regions of stable memory that libraries could use, but only once given a capability to use them. That would, for example, prevent libraries messing with each others’ stable memory invariants. We don’t, off hand, have a good design for this, especially one that allows individuals regions to grow yet remain contiguous with efficient access.

I would not refrain from taking a dependency on the library if it suits your purpose, just be aware that the API may change some time in the future. That being said, I don’t see that happening anytime soon.

Also, be aware that the cost of accessing stable memory is quite high at the moment: even reads and writes of individual words require allocating space in the Wasm heap to do an expensive, particularly when small, bulk transfer from Wasm memory to stable memory, due to the peculiarities of the current System API.

We have some ideas on how replicas could lower these costs substantially, but at the moment they are just ideas and rely on the above Wasm proposals becoming fully available.

7 Likes