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

"flow" op code sanity benchmarks #1433

Merged
merged 20 commits into from
Oct 24, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Description of the upcoming release here.

### Added

- [#1433](https://github.com/FuelLabs/fuel-core/pull/1433): Add "sanity" benchmarks for flow opcodes
- [#1430](https://github.com/FuelLabs/fuel-core/pull/1430): Add "sanity" benchmarks for crypto opcodes
- [#1436](https://github.com/FuelLabs/fuel-core/pull/1436): Add a github action to continuously test beta-4.
- [#1430](https://github.com/FuelLabs/fuel-core/pull/1430): Add "sanity" benchmarks for crypto opcodes.
- [#1437](https://github.com/FuelLabs/fuel-core/pull/1437): Add some transaction throughput tests for basic transfers.
Expand Down
6 changes: 6 additions & 0 deletions benches/benches/block_target_gas.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use block_target_gas_set::{
alu::run_alu,
contract::run_contract,
crypto::run_crypto,
flow::run_flow,
};
use criterion::{
criterion_group,
Expand Down Expand Up @@ -175,8 +177,12 @@ fn block_target_gas(c: &mut Criterion) {

run_alu(&mut group);

run_contract(&mut group);

run_crypto(&mut group);

run_flow(&mut group);

group.finish();
}

Expand Down
20 changes: 20 additions & 0 deletions benches/benches/block_target_gas_set/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::*;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this file?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll probably just keep it since we're gonna add it soon anyway.

// use crate::utils::arb_dependent_cost_values;

pub fn run_contract(_group: &mut BenchmarkGroup<WallTime>) {
// This breaks the benchmarking
// for i in arb_dependent_cost_values() {
// let id = format!("flow/retd_contract opcode {:?}", i);
// run(
// &id,
// group,
// vec![
// op::movi(0x10, i),
// op::retd(RegId::ONE, 0x10),
// op::jmpb(RegId::ZERO, 0),
// ]
// .to_vec(),
// vec![],
// );
// }
}
6 changes: 3 additions & 3 deletions benches/benches/block_target_gas_set/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
utils::generate_linear_costs,
utils::arb_dependent_cost_values,
*,
};
use rand::{
Expand Down Expand Up @@ -135,7 +135,7 @@ pub fn run_crypto(group: &mut BenchmarkGroup<WallTime>) {
.collect(),
);

for i in generate_linear_costs() {
for i in arb_dependent_cost_values() {
let id = format!("crypto/s256 opcode {:?}", i);
run(
&id,
Expand All @@ -152,7 +152,7 @@ pub fn run_crypto(group: &mut BenchmarkGroup<WallTime>) {
)
}

for i in generate_linear_costs() {
for i in arb_dependent_cost_values() {
let id = format!("crypto/k256 opcode {:?}", i);
run(
&id,
Expand Down
188 changes: 188 additions & 0 deletions benches/benches/block_target_gas_set/flow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
use crate::*;

// JMP: Jump
// JI: Jump immediate
// JNE: Jump if not equal
// JNEI: Jump if not equal immediate
// JNZI: Jump if not zero immediate
// JMPB: Jump relative backwards
// JMPF: Jump relative forwards
// JNZB: Jump if not zero relative backwards
// JNZF: Jump if not zero relative forwards
// JNEB: Jump if not equal relative backwards
// JNEF: Jump if not equal relative forwards
// RET: Return from context
pub fn run_flow(group: &mut BenchmarkGroup<WallTime>) {
run(
"flow/jmp opcode",
group,
vec![op::movi(0x10, 0), op::jmp(0x10)],
vec![],
);

run(
"flow/ji opcode",
group,
vec![op::ji(0), op::jmpb(RegId::ZERO, 0)],
vec![],
);

run(
"flow/jne opcode",
group,
vec![
op::movi(0x10, 0),
op::jne(RegId::ZERO, RegId::ONE, 0x10),
op::jmpb(RegId::ZERO, 0),
],
vec![],
);

run(
"flow/jnei opcode",
group,
vec![
op::jnei(RegId::ZERO, RegId::ONE, 0),
op::jmpb(RegId::ZERO, 0),
],
vec![],
);

run(
"flow/jnzi opcode",
group,
vec![op::jnzi(RegId::ONE, 0), op::jmpb(RegId::ZERO, 0)],
vec![],
);

run(
"flow/jmpb opcode",
group,
vec![op::noop(), op::jmpb(RegId::ZERO, 0)],
vec![],
);

run(
"flow/jmpf opcode",
group,
vec![op::jmpf(RegId::ZERO, 0), op::jmpb(RegId::ZERO, 0)],
vec![],
);

run(
"flow/jnzb opcode true",
group,
vec![
op::movi(0x10, 1),
op::noop(),
op::jnzb(0x10, RegId::ZERO, 0),
],
vec![],
);

run(
"flow/jnzb opcode false",
group,
vec![
op::movi(0x10, 0),
op::noop(),
op::jnzb(0x10, RegId::ZERO, 0),
op::jmpb(RegId::ZERO, 0),
],
vec![],
);

run(
"flow/jnzf opcode true",
group,
vec![
op::movi(0x10, 1),
op::noop(),
op::jnzf(0x10, RegId::ZERO, 1),
op::ret(RegId::ZERO),
op::jmpb(RegId::ZERO, 1),
],
vec![],
);

run(
"flow/jnzf opcode false",
group,
vec![
op::movi(0x10, 0),
op::noop(),
op::jnzf(0x10, RegId::ZERO, 1),
op::jmpb(RegId::ZERO, 0),
op::noop(),
],
vec![],
);

run(
"flow/jneb opcode not equal",
group,
vec![
op::movi(0x10, 1),
op::movi(0x11, 0),
op::noop(),
op::jneb(0x10, 0x11, RegId::ZERO, 0),
],
vec![],
);

run(
"flow/jneb opcode equal",
group,
vec![
op::movi(0x10, 1),
op::movi(0x11, 1),
op::noop(),
op::jneb(0x10, 0x11, RegId::ZERO, 0),
op::jmpb(RegId::ZERO, 0),
],
vec![],
);

run(
"flow/jnef opcode not equal",
group,
vec![
op::movi(0x10, 1),
op::movi(0x11, 0),
op::noop(),
op::jnef(0x10, 0x11, RegId::ZERO, 1),
op::ret(RegId::ZERO),
op::jmpb(RegId::ZERO, 1),
],
vec![],
);

run(
"flow/jnef opcode equal",
group,
vec![
op::movi(0x10, 1),
op::movi(0x11, 1),
op::noop(),
op::jnef(0x10, 0x11, RegId::ZERO, 1),
op::jmpb(RegId::ZERO, 0),
op::noop(),
],
vec![],
);

// Don't know how to test "returning" op codes
// run(
// "flow/ret_script opcode",
// group,
// vec![op::ret(RegId::ONE), op::jmpb(RegId::ZERO, 0)].to_vec(),
// vec![],
// );
//
// run(
// "flow/ret_contract opcode",
// group,
// vec![op::ret(RegId::ONE), op::jmpb(RegId::ZERO, 0)].to_vec(),
// vec![],
// );
Comment on lines +174 to +187
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, ret and retd look tricky=D But its price is essential only in the scenario if someone calls another contract and returns from it(and repeats this move many times). Because otherwise, these opcodes return to finish the current execution.

You can skip it for now, but create an issue to write a benchmark later that: the scenario either calls another contract and returns with a lot of data or runs a lot of transactions with this opcode.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added it as a subtask to the parent issue, like we did with gtf.

}
4 changes: 4 additions & 0 deletions benches/benches/block_target_gas_set/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
pub mod alu;

pub mod crypto;

pub mod flow;

pub mod contract;
2 changes: 1 addition & 1 deletion benches/benches/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn make_u256(reg: u8, v: U256) -> Vec<Instruction> {
aloc_bytearray(reg, v.to_be_bytes())
}

pub fn generate_linear_costs() -> Vec<u32> {
pub fn arb_dependent_cost_values() -> Vec<u32> {
let mut linear = vec![1, 10, 100, 1000, 10_000];
let mut l = successors(Some(100_000.0f64), |n| Some(n / 1.5))
.take(5)
Expand Down
2 changes: 1 addition & 1 deletion benches/benches/vm_set/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn run(c: &mut Criterion) {
),
);

let linear = super::utils::generate_linear_costs();
let linear = super::utils::arb_dependent_cost_values();

let mut bench_k256 = c.benchmark_group("k256");
for i in &linear {
Expand Down
13 changes: 3 additions & 10 deletions benches/benches/vm_set/flow.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::iter::successors;

use super::run_group_ref;

use crate::utils::arb_dependent_cost_values;
use criterion::{
Criterion,
Throughput,
};
use fuel_core_benches::*;
use fuel_core_benches::VmBench;
use fuel_core_types::fuel_asm::*;
use rand::{
rngs::StdRng,
Expand All @@ -16,13 +15,7 @@ use rand::{
pub fn run(c: &mut Criterion) {
let rng = &mut StdRng::seed_from_u64(2322u64);

let mut linear = vec![1, 10, 100, 1000, 10_000];
let mut l = successors(Some(100_000.0f64), |n| Some(n / 1.5))
.take(5)
.map(|f| f as u32)
.collect::<Vec<_>>();
l.sort_unstable();
linear.extend(l);
let linear = arb_dependent_cost_values();

run_group_ref(
&mut c.benchmark_group("jmp"),
Expand Down
4 changes: 2 additions & 2 deletions benches/benches/vm_set/mem.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::run_group_ref;

use crate::utils::generate_linear_costs;
use crate::utils::arb_dependent_cost_values;
use criterion::{
Criterion,
Throughput,
Expand Down Expand Up @@ -54,7 +54,7 @@ pub fn run(c: &mut Criterion) {
]),
);

let linear = generate_linear_costs();
let linear = arb_dependent_cost_values();

run_group_ref(
&mut c.benchmark_group("cfei"),
Expand Down
Loading