Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ crate-type = ["cdylib", "lib"]
[[bench]]
name = "compute_units"
harness = false
required-features = ["bpf-entrypoint"]
26 changes: 13 additions & 13 deletions program/benches/compute_units.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#### Compute Units: 2024-10-22 15:36:06.732383 UTC
#### Compute Units: 2024-10-23 12:46:27.264402 UTC

| Name | CUs | Delta |
|------|------|-------|
Expand Down Expand Up @@ -26,16 +26,16 @@
| config_medium_store_10_keys | 7154 | - new - |
| config_medium_store_25_keys | 17341 | - new - |
| config_medium_store_37_keys | 25020 | - new - |
| config_large_init_0_keys | 572 | - new - |
| config_large_init_1_keys | 1151 | - new - |
| config_large_init_5_keys | 2799 | - new - |
| config_large_init_10_keys | 4839 | - new - |
| config_large_init_25_keys | 11591 | - new - |
| config_large_init_37_keys | 16522 | - new - |
| config_large_store_0_keys | 572 | - new - |
| config_large_store_1_keys | 1405 | - new - |
| config_large_store_5_keys | 3969 | - new - |
| config_large_store_10_keys | 7154 | - new - |
| config_large_store_25_keys | 17341 | - new - |
| config_large_store_37_keys | 25020 | - new - |
| config_large_init_0_keys | 693 | - new - |
| config_large_init_1_keys | 1272 | - new - |
| config_large_init_5_keys | 2920 | - new - |
| config_large_init_10_keys | 4961 | - new - |
| config_large_init_25_keys | 11715 | - new - |
| config_large_init_37_keys | 16647 | - new - |
| config_large_store_0_keys | 693 | - new - |
| config_large_store_1_keys | 1526 | - new - |
| config_large_store_5_keys | 4090 | - new - |
| config_large_store_10_keys | 7276 | - new - |
| config_large_store_25_keys | 17465 | - new - |
| config_large_store_37_keys | 25145 | - new - |

50 changes: 12 additions & 38 deletions program/benches/setup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
mollusk_svm_bencher::Bench,
serde::{Deserialize, Serialize},
serde::Serialize,
solana_config_program::{
instruction::store,
state::{ConfigKeys, ConfigState},
Expand Down Expand Up @@ -37,9 +37,10 @@ pub trait BenchSetup: ConfigState + Default {
(ConfigKeys { keys }, Self::default())
}

#[allow(clippy::arithmetic_side_effects)]
fn default_space(keys: Vec<(Pubkey, bool)>) -> usize {
(Self::max_space() + ConfigKeys::serialized_size(keys)) as usize
(Self::max_space()
.checked_add(ConfigKeys::serialized_size(keys))
.unwrap()) as usize
}

fn keys(keys_len: usize) -> Vec<(Pubkey, bool)> {
Expand All @@ -48,8 +49,6 @@ pub trait BenchSetup: ConfigState + Default {
.collect()
}

fn test_store_value() -> Self;

fn init(keys_len: usize) -> BenchContext {
let config_pubkey = Pubkey::new_unique();
let keys = Self::keys(keys_len);
Expand Down Expand Up @@ -80,12 +79,7 @@ pub trait BenchSetup: ConfigState + Default {
let space = Self::default_space(keys.clone());
let lamports = Rent::default().minimum_balance(space);

let instruction = store(
&config_pubkey,
true,
keys.clone(),
&Self::test_store_value(),
);
let instruction = store(&config_pubkey, true, keys.clone(), &Self::default());

let accounts = vec![(
config_pubkey,
Expand All @@ -106,7 +100,7 @@ pub trait BenchSetup: ConfigState + Default {
}

/// A small config, which just stores 8 bytes.
#[derive(Debug, Default, PartialEq, Deserialize, Serialize)]
#[derive(Debug, Default, PartialEq, Serialize)]
pub struct ConfigSmall {
pub item: u64,
}
Expand All @@ -119,17 +113,12 @@ impl ConfigState for ConfigSmall {

impl BenchSetup for ConfigSmall {
const BENCH_ID: &'static str = "config_small";

fn test_store_value() -> Self {
Self { item: 42 }
}
}

/// A medium config, which stores 256 bytes.
#[derive(Debug, Default, PartialEq, Deserialize, Serialize)]
/// A medium config, which stores 1024 bytes.
#[derive(Debug, Default, PartialEq, Serialize)]
pub struct ConfigMedium {
pub hashes: [Hash; 8], // 32 x 8 = 256 bytes
pub rent: Rent,
pub hashes: [Hash; 32], // 32 x 32 = 1024 bytes
}

impl ConfigState for ConfigMedium {
Expand All @@ -140,20 +129,12 @@ impl ConfigState for ConfigMedium {

impl BenchSetup for ConfigMedium {
const BENCH_ID: &'static str = "config_medium";

fn test_store_value() -> Self {
Self {
hashes: [[1; 32].into(); 8],
rent: Rent::default(),
}
}
}

/// A large config, which stores 1024 bytes.
#[derive(Debug, Default, PartialEq, Deserialize, Serialize)]
/// A large config, which stores 32_768 bytes.
#[derive(Debug, Default, PartialEq, Serialize)]
pub struct ConfigLarge {
pub hashes: [Hash; 32], // 32 x 32 = 1024 bytes
pub rent: Rent,
pub hashes: [[Hash; 32]; 32], // 32 x 32 x 32 = 32_768 bytes
}

impl ConfigState for ConfigLarge {
Expand All @@ -164,11 +145,4 @@ impl ConfigState for ConfigLarge {

impl BenchSetup for ConfigLarge {
const BENCH_ID: &'static str = "config_large";

fn test_store_value() -> Self {
Self {
hashes: [[1; 32].into(); 32],
rent: Rent::default(),
}
}
}
10 changes: 6 additions & 4 deletions program/tests/functional.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(feature = "test-sbf")]
// #![cfg(feature = "test-sbf")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this commented out?


use {
bincode::serialized_size,
Expand Down Expand Up @@ -41,11 +41,13 @@ fn setup() -> Mollusk {
Mollusk::new(&solana_config_program::id(), "solana_config_program")
}

#[allow(clippy::arithmetic_side_effects)]
fn get_config_space(key_len: usize) -> usize {
let entry_size = bincode::serialized_size(&(Pubkey::default(), true)).unwrap() as usize;
bincode::serialized_size(&(ConfigKeys::default(), MyConfig::default())).unwrap() as usize
+ key_len * entry_size
let total_keys_size = (key_len).checked_mul(entry_size).unwrap();
bincode::serialized_size(&(ConfigKeys::default(), MyConfig::default()))
.ok()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is the ok() needed? I thought you could just do and_then on the Result: https://doc.rust-lang.org/std/result/enum.Result.html#method.and_then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only did it because checked_add returns an option, so it was one less unwrap(). I suppose it's all the same, though.

.and_then(|s| s.checked_add(total_keys_size as u64))
.unwrap() as usize
}

fn create_config_account(mollusk: &Mollusk, keys: Vec<(Pubkey, bool)>) -> AccountSharedData {
Expand Down
3 changes: 1 addition & 2 deletions scripts/program/lint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
// ['--arg1', '--arg2', ...cliArguments()]
const lintArgs = [
'-Zunstable-options',
'--tests',
'--benches',
'--all-targets',
'--features',
'bpf-entrypoint,test-sbf',
'--',
Expand Down