Are there cycle limits on preupgrade and postupgrade? I would imagine that large hashmaps, lists, etc being output to an array will take some significant cycles once they get pretty large. Likewise, loading a few hundred thousand items out of an array into a HashMap will take some time as well.
The cycles limits are enforced at the message level not at the pre/post upgrade canister method level. You can find the definition here:
If you have inefficient serialization/deserialization of your stable memory data in those pre/post hooks, you can hit the execution message limit. If you hit this limit, your state will not be committed (it’ll roll back) but the cycles that’ve been consumed will be deducted from your canister’s cycle balance.
Does it mean that if my canister hits a limit and preupgrade method will never succeed - I will never be able to “upgrade” my canister? The only way to change the code will be “reinstall”?
It’s a little disappointing to read that Motoko stable variables are not recommended for use due to:
Motoko serializing stable variables into the main wasm memory before copying the bytes into stable memory (thus making a 4 GB canister memory limit more like 2 GB)
the aforementioned instruction limit on the pre-upgrade and post-upgrade hooks
I’m really hoping these will be addressed soon, as Motoko stable variables are the first place new IC developers turn to having read the docs.