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

feat(bench): make benchmark inputs deterministic using fixed seed #13586

Merged
merged 11 commits into from
Dec 30, 2024

Conversation

DeVikingMark
Copy link
Contributor

@DeVikingMark DeVikingMark commented Dec 28, 2024

Towards #13535

Description of Changes

Made benchmark inputs deterministic by using a fixed seed for all random number generators. This resolves the issue of noise in test results on codspeed.

The changes include:

  • Added a fixed seed (12345) for all TestRunner instances.
  • Used the ChaCha algorithm for RNG, ensuring deterministic results.
  • Updated the following benchmarks:
    • crates/trie/sparse/benches/rlp_node.rs
    • crates/trie/sparse/benches/root.rs
    • crates/trie/trie/benches/trie_root.rs
    • crates/transaction-pool/benches/priority.rs

Testing

  • Ran benchmarks multiple times to verify reproducibility of results.
  • Confirmed that results remain stable across runs.

Additional Notes

This change does not affect the functionality of the code itself but ensures that benchmark results are more stable and reproducible.

Copy link
Member

@Rjected Rjected left a comment

Choose a reason for hiding this comment

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

thanks! I have some suggestions on reducing some TestRunner setup lines

Comment on lines 67 to 88
fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("priority");
group.sample_size(10);

let config = ProptestConfig {
rng_algorithm: prop::test_runner::RngAlgorithm::ChaCha,
seed: 12345,
..Default::default()
};

let mut group = c.benchmark_group("Blob priority calculation");
let fee_jump_input = generate_test_data_fee_delta();

// Unstable sorting of unsorted collection
fee_jump_bench(&mut group, "BenchmarkDynamicFeeJumpCalculation", fee_jump_input);

let blob_priority_input = generate_test_data_priority();

// BinaryHeap that is resorted on each update
priority_bench(&mut group, "BenchmarkPriorityCalculation", blob_priority_input);
}

Copy link
Member

Choose a reason for hiding this comment

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

we should be making the existing benches deterministic, instead of adding a new bench

Comment on lines 19 to 23
let mut runner = TestRunner::new(ProptestConfig {
rng_algorithm: prop::test_runner::RngAlgorithm::ChaCha,
seed: 12345,
..Default::default()
});
Copy link
Member

Choose a reason for hiding this comment

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

this should be using let mut runner = TestRunner::deterministic(); instead

@@ -30,7 +30,11 @@ pub fn trie_root_benchmark(c: &mut Criterion) {

fn generate_test_data(size: usize) -> Vec<ReceiptWithBloom<Receipt>> {
prop::collection::vec(arb::<ReceiptWithBloom<Receipt>>(), size)
.new_tree(&mut TestRunner::new(ProptestConfig::default()))
.new_tree(&mut TestRunner::new(ProptestConfig {
Copy link
Member

Choose a reason for hiding this comment

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

same nit re: using the deterministic runner

Comment on lines 217 to 221
let mut runner = TestRunner::new(ProptestConfig {
rng_algorithm: prop::test_runner::RngAlgorithm::ChaCha,
seed: 12345,
..Default::default()
});
Copy link
Member

Choose a reason for hiding this comment

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

same nit re: using the deterministic runner

@DeVikingMark
Copy link
Contributor Author

@Rjected I made some changes, could you pls review them? tnx

Copy link
Member

@Rjected Rjected left a comment

Choose a reason for hiding this comment

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

thanks! almost there, looks like compile error is caused by an artifact of older changes?

Comment on lines 53 to 55
let mut group = c.benchmark_group("priority");
group.sample_size(10);

Copy link
Member

Choose a reason for hiding this comment

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

seems like this needs to be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems like this needs to be removed?

you're right, I changed, it seems to be that this one is what we need, or am I trippin'?

Copy link
Member

@Rjected Rjected left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

@Rjected Rjected requested a review from gakonst as a code owner December 30, 2024 20:48
Copy link

codspeed-hq bot commented Dec 30, 2024

CodSpeed Performance Report

Merging #13586 will improve performances by ×3.5

Comparing DeVikingMark:potuzhniy (a698607) with main (0b135a2)

Summary

⚡ 22 improvements
✅ 55 untouched benchmarks

Benchmarks breakdown

Benchmark main DeVikingMark:potuzhniy Change
`hash builder[init size 1000 update size 100 num updates 10]` 31.5 ms
`hash builder[init size 1000 update size 100 num updates 5]` 14.4 ms
`hash builder[init size 1000 update size 1000 num updates 10]` 196.1 ms
`hash builder[init size 1000 update size 1000 num updates 1]` 9.8 ms
`hash builder[init size 1000 update size 1000 num updates 3]` 39.2 ms
`hash builder[init size 1000 update size 1000 num updates 5]` 78 ms
`hash builder[init size 10000 update size 1000 num updates 10]` 310.4 ms
`hash builder[init size 10000 update size 1000 num updates 5]` 141.1 ms
`sparse trie[init size 1000 update size 100 num updates 10]` 15.6 ms
`sparse trie[init size 1000 update size 100 num updates 1]` 1.6 ms
`sparse trie[init size 1000 update size 100 num updates 3]` 4.3 ms
`sparse trie[init size 1000 update size 100 num updates 5]` 7.7 ms
`sparse trie[init size 1000 update size 1000 num updates 10]` 122.3 ms
`sparse trie[init size 1000 update size 1000 num updates 1]` 8.7 ms
`sparse trie[init size 1000 update size 1000 num updates 3]` 29 ms
`sparse trie[init size 1000 update size 1000 num updates 5]` 53 ms
`sparse trie[init size 10000 update size 100 num updates 10]` 30.9 ms
`sparse trie[init size 10000 update size 100 num updates 5]` 17.9 ms
`sparse trie[init size 10000 update size 1000 num updates 10]` 156.8 ms
`sparse trie[init size 10000 update size 1000 num updates 1]` 18.8 ms
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

@Rjected Rjected added this pull request to the merge queue Dec 30, 2024
@DeVikingMark
Copy link
Contributor Author

lgtm, thanks!

It was a pleasure to help you 🫡 Could you pls merge it? :)

Merged via the queue into paradigmxyz:main with commit 5629ba0 Dec 30, 2024
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants