Is there a performance overhead from using the instruction counter inside a canister?

Is there significant overhead in cycle usage from using the instruction counter within a canister deployed to mainnet?

Is the cost from using the instruction counter constant O(1), or does it grow by a factor of the total instructions executed O(n)?

2 Likes

There is some cost as with any other system api that is called (I assume you’re referring to the performance counter system api, let me know if not). The api is very simple though so it’s one of the lowest in cost and it’s constant as the work done does not depend on input (e.g. number of bytes read/written in other cases).

That said, I think it’s negligible in practice, so unless you call it in a tight loop it’s unlikely you’ll notice anything on your end.

4 Likes