Abstract away the 4GB canister memory limit

Disclaimer: the opinions below are my own, not official DFINITY position.

I think Wasm32 has some benefits:

  1. Your program might end up using significantly less memory because all the pointers and sizes occupy 4 bytes, not 8 bytes. At least that’s what people observed when they started to recompile old 32bit applications for 64bit platforms a decade ago.
  2. The Wasm compiler can generate much more efficient code because there is no need to do bounds checking on every memory access. This only works because the replica can fully embed canister memory into its address space. This won’t fly with Wasm64. For developers, efficient execution = cheaper gas on average. This point might become less important once Wasm bulk memory operations proposal is adopted.

64-bit address space would indeed allow you to store more, but probably not orders of magnitude more. I don’t think there can be a general solution that would allow one to scale linear memory across multiple subnets, for example, that would require some very complicated and expensive mechanisms.

Upgrades are another big factor. When you deploy a new version of your canister, the whole linear memory is discarded. We do it because if you change your program a bit and recompile, the effects on the memory layout are unpredictable. We experimented with deploying minimal changes (add one function call) without discarding the linear memory, with no success. Upgrade instruction limit will not allow one to shift around gigabytes of data when you deploy a new version of your canister, so using linear memory only for transient data is probably the way to go for canisters that need to handle large amounts of data.

Scaling stable memory to larger sizes is straightforward with the current implementation of the replica and I won’t be surprised if this happens quite soon. This will require new efficient approaches to working with stable memory directly instead of using canister linear memory as the main data storage. We’re working hard to provide an efficient and easy to use solution to that problem.

As a canister developer myself (I worked, e.g., on certified assets canister and internet identity backend), I’m not particularly concerned about the 4GiB linear memory limit. If the stable memory restrictions are lifted, you’ll be able to utilize most of the subnet TPS capacity with just a single canister. And if you need more capacity, you’ll probably have to plan for a multi-subnet multi-canister setup anyways, and a huge address space won’t help you much here.

11 Likes