Complexity Error

I’m encountering the following error while deploying my Motoko canister:

I’d like to understand what this error means and how I can resolve it.

The replica returned a rejection error: reject code CanisterError, reject message Error from Canister vizcg-th777-77774-qaaea-cai: Canister’s Wasm module is not valid: Wasm module contains a function at index 0 with complexity 1013027 which exceeds the maximum complexity allowed 1000000..
Try breaking large functions up into multiple smaller functions. See documentation: https://internetcomputer.org/docs/current/references/execution-errors#wasm-module-function-complexity-too-high, error code Some(“IC0505”)

1 Like

Which version of dfx/moc are you using and are you using –enhanced-orthogonal-persistence? I recently fixed a bug that produced the same error.

The bug should be fixed in moc 0.14.12 and higher (0.14.13 is shipped with dfx 0.28)

2 Likes

Hey, I use:

dfx 0.27.0,
with enhanced-orthogonal-persistence
Motoko compiler 0.14.8 (source rfs7jcpa-8l1n9bax-azlf9hwm-qbaqv832)

Based on what I observed using wasm-objdump, I’m not entirely sure if my interpretation is accurate.

Key Findings:

  1. Total Functions: 4,995 functions in your Wasm module
  2. Wasm File Size: 1.1MB

Largest Functions:

  • initialize_root_array: 227,476 bytes (this is the main culprit!)
  • incremental_gc: 10,500 bytes
  • getTasksByFilter: 5,298 bytes
  • Various deserialization functions: 5,000-6,000 bytes each

The fix for this went out with Motoko 0.14.12. The upcoming dfx 0.28 will include it: sdk/CHANGELOG.md at master · dfinity/sdk · GitHub

Thanks! After updating to DFX version 0.28, it seems to be working now.

1 Like