Depending on the seed you can save a lot of CU saving the bumb in an account.
This is because to find a PDA that is off curve internally anchor calls
create_program_address repedadly with decreasing bumbs until it finds a PDA thats not on the curve.
Here is one example:
// 12,136 CUs
compute_fn! { "Find PDA" =>
Pubkey::find_program_address(&[b"counter"], ctx.program_id);
}
// 1,651 CUs
compute_fn! { "Find PDA" =>
Pubkey::create_program_address(&[b"counter", &[248_u8]], &program_id).unwrap();
}
In anchor:
// 12,136 CUs when not defining the bump
#[account(
seeds = [b"counter"],
bump
)]
// only 1600 if using the bump that is saved in the counter_checked account
#[account(
seeds = [b"counter"],
bump = counter_checked.bump
)]
So here you would have a u8 field in the counter_checked account and set it when you initialize it. Then you can just always use that cached bump when you call an instruction.
Here is a guide explaining the optimization:
https://solana.com/de/developers/guides/advanced/how-to-optimize-compute
and here a test you can run to try it yourself:
https://github.com/solana-developers/cu_optimizations/blob/main/anchor/counter/anchor/programs/counter/src/lib.rs#L18