Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmark compute-budget instructions #3614

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ members = [
"programs/bpf_loader",
"programs/bpf_loader/gen-syscall-list",
"programs/compute-budget",
"programs/compute-budget-bench",
"programs/config",
"programs/ed25519-tests",
"programs/loader-v4",
Expand Down
24 changes: 24 additions & 0 deletions programs/compute-budget-bench/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "solana-compute-budget-program-bench"
publish = false
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unpublished

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 programs/compute-budget-bench/benches/compute_budget.rs
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);
Loading