forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Benchmark compute-budget instructions (solana-labs#3614)
* Benchmark compute-budget instructions * Move bench to separate and unpublished crate to break circular dependency
- Loading branch information
1 parent
aeb5518
commit be47703
Showing
4 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[package] | ||
name = "solana-compute-budget-program-bench" | ||
publish = false | ||
version = { workspace = true } | ||
authors = { workspace = true } | ||
repository = { workspace = true } | ||
homepage = { workspace = true } | ||
license = { workspace = true } | ||
edition = { workspace = true } | ||
|
||
[dependencies] | ||
criterion = { workspace = true } | ||
solana-compute-budget = { workspace = true } | ||
solana-compute-budget-program = { workspace = true } | ||
solana-runtime-transaction = { workspace = true } | ||
solana-sdk = { workspace = true } | ||
solana-svm-transaction = { workspace = true } | ||
|
||
[[bench]] | ||
name = "compute_budget" | ||
harness = false | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] |
136 changes: 136 additions & 0 deletions
136
programs/compute-budget-bench/benches/compute_budget.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
use { | ||
criterion::{black_box, criterion_group, criterion_main, Criterion}, | ||
solana_compute_budget::compute_budget_limits::ComputeBudgetLimits, | ||
solana_runtime_transaction::instructions_processor::process_compute_budget_instructions, | ||
solana_sdk::{compute_budget::ComputeBudgetInstruction, instruction::CompiledInstruction}, | ||
solana_svm_transaction::instruction::SVMInstruction, | ||
std::num::NonZero, | ||
}; | ||
|
||
const ONE_PAGE: u32 = 32 * 1024; | ||
const SIXTY_FOUR_MB: u32 = 64 * 1024 * 1024; | ||
|
||
fn bench_request_heap_frame(c: &mut Criterion) { | ||
let instruction = [( | ||
solana_sdk::compute_budget::id(), | ||
CompiledInstruction::new_from_raw_parts( | ||
0, | ||
ComputeBudgetInstruction::request_heap_frame(ONE_PAGE).data, | ||
vec![], | ||
), | ||
)]; | ||
|
||
c.bench_function("request_heap_limit", |bencher| { | ||
bencher.iter(|| { | ||
assert_eq!( | ||
process_compute_budget_instructions(black_box( | ||
instruction | ||
.iter() | ||
.map(|(id, ix)| (id, SVMInstruction::from(ix))) | ||
)), | ||
Ok(ComputeBudgetLimits { | ||
updated_heap_bytes: ONE_PAGE, | ||
compute_unit_limit: 0, | ||
compute_unit_price: 0, | ||
loaded_accounts_bytes: NonZero::new(SIXTY_FOUR_MB).unwrap() | ||
}) | ||
) | ||
}) | ||
}); | ||
} | ||
|
||
fn bench_set_compute_unit_limit(c: &mut Criterion) { | ||
let instruction = [( | ||
solana_sdk::compute_budget::id(), | ||
CompiledInstruction::new_from_raw_parts( | ||
0, | ||
ComputeBudgetInstruction::set_compute_unit_limit(1024).data, | ||
vec![], | ||
), | ||
)]; | ||
|
||
c.bench_function("set_compute_unit_limit", |bencher| { | ||
bencher.iter(|| { | ||
assert_eq!( | ||
process_compute_budget_instructions(black_box( | ||
instruction | ||
.iter() | ||
.map(|(id, ix)| (id, SVMInstruction::from(ix))) | ||
)), | ||
Ok(ComputeBudgetLimits { | ||
updated_heap_bytes: ONE_PAGE, | ||
compute_unit_limit: 1024, | ||
compute_unit_price: 0, | ||
loaded_accounts_bytes: NonZero::new(SIXTY_FOUR_MB).unwrap() | ||
}) | ||
) | ||
}) | ||
}); | ||
} | ||
|
||
fn bench_set_compute_unit_price(c: &mut Criterion) { | ||
let instruction = [( | ||
solana_sdk::compute_budget::id(), | ||
CompiledInstruction::new_from_raw_parts( | ||
0, | ||
ComputeBudgetInstruction::set_compute_unit_price(1).data, | ||
vec![], | ||
), | ||
)]; | ||
|
||
c.bench_function("set_compute_unit_price", |bencher| { | ||
bencher.iter(|| { | ||
assert_eq!( | ||
process_compute_budget_instructions(black_box( | ||
instruction | ||
.iter() | ||
.map(|(id, ix)| (id, SVMInstruction::from(ix))) | ||
)), | ||
Ok(ComputeBudgetLimits { | ||
updated_heap_bytes: ONE_PAGE, | ||
compute_unit_limit: 0, | ||
compute_unit_price: 1, | ||
loaded_accounts_bytes: NonZero::new(SIXTY_FOUR_MB).unwrap() | ||
}) | ||
) | ||
}) | ||
}); | ||
} | ||
|
||
fn bench_set_loaded_accounts_data_size_limit(c: &mut Criterion) { | ||
let instruction = [( | ||
solana_sdk::compute_budget::id(), | ||
CompiledInstruction::new_from_raw_parts( | ||
0, | ||
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(1).data, | ||
vec![], | ||
), | ||
)]; | ||
|
||
c.bench_function("set_loaded_accounts_data_size_limit", |bencher| { | ||
bencher.iter(|| { | ||
assert_eq!( | ||
process_compute_budget_instructions(black_box( | ||
instruction | ||
.iter() | ||
.map(|(id, ix)| (id, SVMInstruction::from(ix))) | ||
)), | ||
Ok(ComputeBudgetLimits { | ||
updated_heap_bytes: ONE_PAGE, | ||
compute_unit_limit: 0, | ||
compute_unit_price: 0, | ||
loaded_accounts_bytes: NonZero::new(1).unwrap() | ||
}) | ||
) | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!( | ||
benches, | ||
bench_request_heap_frame, | ||
bench_set_compute_unit_limit, | ||
bench_set_compute_unit_price, | ||
bench_set_loaded_accounts_data_size_limit, | ||
); | ||
criterion_main!(benches); |