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

Fixing incorrect measurement for fast(µs) opcodes #1457

Merged
merged 3 commits into from
Oct 26, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
Description of the upcoming release here.

### Added
- [#1457](https://github.com/FuelLabs/fuel-core/pull/1457): Fixing incorrect measurement for fast(µs) opcodes.
- [#1449](https://github.com/FuelLabs/fuel-core/pull/1449): fix coin pagination in e2e test client
- [#1447](https://github.com/FuelLabs/fuel-core/pull/1447): Add timeout for continuous e2e tests
- [#1444](https://github.com/FuelLabs/fuel-core/pull/1444): Add "sanity" benchmarks for memory opcodes.
Expand Down
48 changes: 35 additions & 13 deletions benches/benches/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use criterion::{
BenchmarkGroup,
Criterion,
};
use std::time::Duration;

use fuel_core_benches::*;
use fuel_core_storage::transactional::Transaction;
Expand Down Expand Up @@ -41,25 +40,48 @@ where
db_txn
};

let mut elapsed_time = Duration::default();
for _ in 0..iters {
let final_time;
loop {
// Measure the total time to revert the VM to the initial state.
// It should always do the same things regardless of the number of
// iterations because we use a `diff` from the `VmBenchPrepared` initialization.
let start = std::time::Instant::now();
match instruction {
Instruction::CALL(call) => {
let (ra, rb, rc, rd) = call.unpack();
vm.prepare_call(ra, rb, rc, rd).unwrap();
}
_ => {
black_box(vm.instruction(*instruction).unwrap());
for _ in 0..iters {
vm.reset_vm_state(diff);
Copy link
Member

Choose a reason for hiding this comment

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

Is this actually measuring anything? It seems like this would essentially be a noop if we haven't executed any instructions yet 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

During setup of the bench we run instruction one time to take a diff
image

Copy link
Member

Choose a reason for hiding this comment

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

Have we run the benchmarks to see how much of an improvement this is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, now it produces more stable results
image
image

Copy link
Member

Choose a reason for hiding this comment

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

that's great!

}
let time_to_reset = start.elapsed();

let start = std::time::Instant::now();
for _ in 0..iters {
match instruction {
Instruction::CALL(call) => {
let (ra, rb, rc, rd) = call.unpack();
vm.prepare_call(ra, rb, rc, rd).unwrap();
}
_ => {
black_box(vm.instruction(*instruction).unwrap());
}
}
vm.reset_vm_state(diff);
}
let only_instruction = start.elapsed().checked_sub(time_to_reset);

// It may overflow when the benchmarks run in an unstable environment.
// If the hardware is busy during the measuring time to reset the VM,
// it will produce `time_to_reset` more than the actual time
// to run the instruction and reset the VM.
if let Some(result) = only_instruction {
final_time = result;
break
} else {
println!("The environment is unstable. Rerunning the benchmark.");
}
elapsed_time += start.elapsed();
vm.reset_vm_state(diff);
}

db_txn.commit().unwrap();
// restore original db
*vm.as_mut().database_mut() = original_db;
elapsed_time
final_time
})
});
}
Expand Down
Loading