I have recently noticed that some of my tests were performing close to max computation units and would exceed 200,000 units used on some runs but not on others despite the tests having the same layout and being run with the same overall setup

Is this normal, like can contract level calls take up more or less computation units quasi-randomly depending on the slot of the transaction? Another guy reported similar findings in the Solana discord, is this a bug or a feature, does anybody have any idea?

2 Answers 2


A big cause of non-deterministic variability in compute units is usually the find_program_address call. If you randomly generate a keypair in your tests, and then use that keypair as a seed in a PDA derivation, the call will loop through potential bumps until an off curve address is found. The amount of loops required won't always be the same and the typical range is somewhere between 1800 and 7000 CUs to derive a PDA on chain. This can compound if you have multiple derivations or any programs you CPI into use find_program_address.


Do you have any CPI's in the contract? these tend to contribute heavily to the compute unit.

Compute units will change based on the heap/stack allocation of the runtime so if you have conditional logic within the contract this will result in marginally different CU cost

  • 1
    Oh, got it. But does that mean that whether a program call that uses close to max compute units succeeds or not is quasi-random? This seems quite antithetical to the idea of Solana as a State Machine.....
    – Tanmay
    Commented Jul 14, 2023 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.