docs

Compute

Overview

Benchmarkfuzz/tests/compute.rs, in the fuzzer's litesvm world
Program buildtarget/deploy/unwind.so, built with --features devnet
GateA row more than 10% over its recorded budget fails the test
Recorded numbersNone yet

A Solana transaction gets at most 1.4 million compute units, and every instruction here runs inside one. The benchmark runs the compiled program, not a Rust build of it, so what it reports is what a validator would charge.

It loads the program into litesvm the way the stateful fuzzer does (fuzz/tests/support/env.rs) and bootstraps the same main fixture: three Pyth markets, one keeper-priced market, one folded market and two custodies. A fixed script then walks each path below once. The count for each row is the program's own consumed N of M compute units log line. That covers the token transfers the instruction makes, and not the compute-budget instruction in front of it.

Running it

anchor build -- --features devnet
cd fuzz
cargo test --release --test compute -- --nocapture

The test prints a table with one row per path: what it consumed and its budget. The numbers are deterministic for one build of the program. Run it before and after a change, and a moved number is the change's doing.

What is measured

RowPath
clear_batch, emptyA due batch with no orders seals and reopens
submit_order, openA taker's first open in a market, which creates the position
clear_batch, 1 orderThat one open against the pool's quote
settle_order, openSettling it into the position
cancel_batch_orderA resting open withdrawn, its collateral returned
submit_order, closeA reduce-only order for the whole position
settle_order, closeSettling it at its flow's clearing price, the payout transferred
submit_flipA long turned short in one order: its close half and open half into the batch
settle_order, flipIts open half settled first, which settles the close half in the same instruction
clear_batch, 32 ordersHalf a batch of takers, buyers and sellers
clear_batch, 64 ordersA full batch
push_markA keeper's push to an observed market
observeA permissionless fold of a pool reading into an observed mark
accrue_fundingOne market's funding brought up to now
checkpoint_aum, every marketA fresh AUM checkpoint across all five markets
add_liquidityAn LP deposit
request_withdrawLP shares put into escrow
cancel_withdrawThe escrow returned
claim_withdrawA claim after the cooldown
step_risk_priceOne step of the risk price after a 25% drop
liquidateA 5x long liquidated after that drop

Recorded numbers

None yet. The SBF toolchain (cargo-build-sbf) was not available where the benchmark was written, so the program could not be built and nothing was measured. Nothing here is estimated.

To record them, run the benchmark, copy its table here, and copy each row's count into BUDGET in fuzz/tests/compute.rs. From then on the test fails when a row grows past its budget by more than 10%. A change that costs compute on purpose records the new number in both places, in the same commit.

On this page