Programmatically measure cycles consumption

Cycles are simply a weighted sum of Wasm instruction counts. Some system APIs are more expensive than others, e.g. bulk memory access, stable memory. If the Wasm instruction doesn’t access the stored data, there is no charge. So all cost can be computed from the instruction counts, and it’s safe to measure cycle consumption before and after the function call.

If you use Motoko Playground, and enable profiling while deploy, we can draw a flamegraph for each update call, so that you can understand which function costs the most.

The design doc is here: IC-822 Canister profiling - Google Docs

7 Likes