How to debug a function with too high complexity?

Trying to compile my project (compiling pst.mo).

$ make deploy@pst
...
Deploying: pst
All canisters have already been created.
Error: Failed while trying to deploy canisters.
Caused by: Failed while trying to install all canisters.
Caused by: Failed to install wasm module to canister 'pst'.
Caused by: Failed during wasm installation call
Caused by: The replica returned a rejection error: reject code CanisterError, reject message Error from Canister zqicb-5x777-77774-qabla-cai: Canister's Wasm module is not valid: Wasm module contains a function at index 0 with complexity 1019374 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")

How to determine which function is at index 0?

I tried:

wasm-objdump -x .dfx/local/canisters/pst/pst.wasm

but from the output I cannot understand, which function is at index 0, because I don’t know how this index is displayed.

Is function 0 the initialization of the actor, rather than a literal func?

The index here refers to the index within the Wasm’s function section. So if you run wasm-objdump -j Function -x .dfx/local/canisters/pst/pst.wasm it’ll be the first one. But it’s also possible that this function is generated by the motoko compiler and not directly related to the code you wrote (cc @claudio @alex-df) - could you also post the output of that command?

hey there, thank you for reaching out.

We’ve seen something similar recently and we released a series of fixes to cover it. The latest release of the moc compiler has these, it will probably take a bit longer until dfx gets up to date.

Import[33]:
 - func[0] sig=17 <ic0.call_data_append> <- ic0.call_data_append

That looks like the first import (you’re looking at the Import section). This error is coming from the first function defined in your module which would be at the top of the Function section.

I don’t have a function named call_data_append.

Release 0.14.12 · dfinity/motoko · GitHub should fix this, but it’s not in dfx yet.

You should be able to use this release of Motoko, side-loaded, with dfx 0.27.0 or higher, I think.