Why is canister code size limited to 2MB?

I wonder, why for gigabytes-sized canister, the code is limited to just about 2MB.

Error: Failed while trying to deploy canisters.
Caused by: Failed while trying to deploy canisters.
  Failed while trying to install all canisters.
    Failed to install wasm module to canister 'zon_backend'.
      Failed during wasm installation call: The replica returned an HTTP Error: Http Error: status 413 Payload Too Large, content type "text/plain", content: Request 0x096f602ed01cd12abeb415a80142d338782e6e9b51254a62b84876fb5b7cee26 is too large. Message byte size 2607151 is larger than the max allowed 2097152.

Is there a way to increase allowed code size?

I am using DFX 0.14.3.

While not immediately obvious, the answer is in the error message: The replica returned an HTTP Error: Http Error: status 413 Payload Too Large [...] Message byte size 2607151 is larger than the max allowed 2097152.

It’s not the canister code size that is limited to 2 MB, but the ingress message payload size. Maximum block size is 4 MB, so allowing ingress messages larger than 2 MB is probably unwise (and ingress messages above 4 MB would be impossible).

One workaround (also used by the NNS) is to upload the Wasm in chunks, into a canister on the same subnet. And have that canister issue the install_code() call. Subnet-local canister messages may have payloads of up to 10 MB (cross-subnet ones are also limited to 2 MB, for the same reason that ingress message payloads are).

AFAIK the Execution team is working on addressing this issue, by allowing chunked upload of canister Wasm straight to the management canister, rather than requiring a second canister and an elaborate setup. Not sure whether this includes raising the hard limit above 10 MB or not.

2 Likes