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

Update fuel-vm to 0.31 for gas benchmarks #1166

Merged
merged 8 commits into from
Apr 28, 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
32 changes: 16 additions & 16 deletions Cargo.lock

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

30 changes: 19 additions & 11 deletions benches/benches/set/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use criterion::{
Criterion,
Throughput,
};
use fuel_core::database::vm_database::VmDatabase;
use fuel_core_benches::*;
use fuel_core_storage::ContractsAssetsStorage;
use fuel_core_types::{
Expand Down Expand Up @@ -251,7 +252,7 @@ pub fn run(c: &mut Criterion) {
op::add(0x15, 0x15, 0x15),
op::addi(0x15, 0x15, 32),
op::aloc(0x15),
op::addi(0x15, RegId::HP, 1),
op::move_(0x15, RegId::HP),
];

ccp.throughput(Throughput::Bytes(i));
Expand Down Expand Up @@ -308,7 +309,7 @@ pub fn run(c: &mut Criterion) {
VmBench::new(op::bhsh(0x10, RegId::ZERO)).with_prepare_script(vec![
op::movi(0x10, Bytes32::LEN.try_into().unwrap()),
op::aloc(0x10),
op::addi(0x10, RegId::HP, 1),
op::move_(0x10, RegId::HP),
]),
);

Expand All @@ -332,7 +333,7 @@ pub fn run(c: &mut Criterion) {
VmBench::new(op::cb(0x10)).with_prepare_script(vec![
op::movi(0x10, Bytes32::LEN.try_into().unwrap()),
op::aloc(0x10),
op::addi(0x10, RegId::HP, 1),
op::move_(0x10, RegId::HP),
]),
);

Expand Down Expand Up @@ -404,7 +405,7 @@ pub fn run(c: &mut Criterion) {
op::gtf_args(0x16, 0x00, GTFArgs::ScriptData),
op::movi(0x15, 2000),
op::aloc(0x15),
op::addi(0x14, RegId::HP, 1),
op::move_(0x14, RegId::HP),
]);
run_group_ref(&mut c.benchmark_group("croo"), "croo", input);
}
Expand All @@ -426,14 +427,21 @@ pub fn run(c: &mut Criterion) {
for i in linear.clone() {
let mut input = VmBench::contract(rng, op::smo(0x15, 0x16, 0x17, 0x18))
.expect("failed to prepare contract");
let index = input.outputs.len() - 1;
input.prepare_db = Some(Box::new(|mut db: VmDatabase| {
db.merkle_contract_asset_id_balance_insert(
&ContractId::default(),
&AssetId::default(),
Word::MAX,
)?;
Ok(db)
}));
input.post_call.extend(vec![
op::gtf_args(0x15, 0x00, GTFArgs::ScriptData),
// Offset 32 + 8+ 8 + 32
op::addi(0x15, 0x15, 32 + 8 + 8 + 32),
op::movi(0x16, i.try_into().unwrap()),
op::movi(0x17, index.try_into().unwrap()),
op::movi(0x18, 10),
// Offset 32 + 8 + 8 + 32
op::addi(0x15, 0x15, 32 + 8 + 8 + 32), // target address pointer
op::addi(0x16, 0x15, 32), // data ppinter
op::movi(0x17, i.try_into().unwrap()), // data length
op::movi(0x18, 10), // coins to send
]);
input.data.extend(
Address::new([1u8; 32])
Expand Down Expand Up @@ -475,7 +483,7 @@ pub fn run(c: &mut Criterion) {
op::muli(0x15, 0x15, 32),
op::addi(0x15, 0x15, 1),
op::aloc(0x15),
op::addi(0x14, RegId::HP, 1),
op::move_(0x14, RegId::HP),
];
let mut bench = VmBench::contract(rng, op::srwq(0x14, 0x11, 0x27, 0x16))
.expect("failed to prepare contract")
Expand Down
6 changes: 3 additions & 3 deletions benches/benches/set/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn run(c: &mut Criterion) {
op::addi(0x22, 0x21, message.as_ref().len().try_into().unwrap()),
op::movi(0x10, PublicKey::LEN.try_into().unwrap()),
op::aloc(0x10),
op::addi(0x11, RegId::HP, 1),
op::move_(0x11, RegId::HP),
])
.with_data(signature.iter().chain(message.iter()).copied().collect()),
);
Expand All @@ -41,7 +41,7 @@ pub fn run(c: &mut Criterion) {
.with_prepare_script(vec![
op::movi(0x10, Bytes32::LEN.try_into().unwrap()),
op::aloc(0x10),
op::addi(0x10, RegId::HP, 1),
op::move_(0x10, RegId::HP),
op::movi(0x11, 32),
])
.with_data(signature.iter().chain(message.iter()).copied().collect()),
Expand All @@ -54,7 +54,7 @@ pub fn run(c: &mut Criterion) {
.with_prepare_script(vec![
op::movi(0x10, Bytes32::LEN.try_into().unwrap()),
op::aloc(0x10),
op::addi(0x10, RegId::HP, 1),
op::move_(0x10, RegId::HP),
op::movi(0x11, 32),
])
.with_data(signature.iter().chain(message.iter()).copied().collect()),
Expand Down
36 changes: 25 additions & 11 deletions benches/benches/set/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ use criterion::{
use fuel_core_benches::*;
use fuel_core_types::fuel_asm::*;

/// Set a register `r` to a Word-sized number value using left-shifts
fn set_full_word(r: RegisterId, v: Word) -> Vec<Instruction> {
let r = u8::try_from(r).unwrap();
let mut ops = vec![op::movi(r, 0)];
for byte in v.to_be_bytes() {
ops.push(op::ori(r, r, byte as u16));
ops.push(op::slli(r, r, 8));
}
ops.pop().unwrap(); // Remove last shift
ops
}

pub fn run(c: &mut Criterion) {
run_group_ref(
&mut c.benchmark_group("lb"),
Expand All @@ -27,7 +39,7 @@ pub fn run(c: &mut Criterion) {
"sb",
VmBench::new(op::sb(0x10, 0x11, 0)).with_prepare_script(vec![
op::aloc(RegId::ONE),
op::addi(0x10, RegId::HP, 1),
op::move_(0x10, RegId::HP),
op::movi(0x11, 50),
]),
);
Expand All @@ -38,7 +50,7 @@ pub fn run(c: &mut Criterion) {
VmBench::new(op::sw(0x10, 0x11, 0)).with_prepare_script(vec![
op::movi(0x10, 8),
op::aloc(0x10),
op::addi(0x10, RegId::HP, 1),
op::move_(0x10, RegId::HP),
op::movi(0x11, 50),
]),
);
Expand Down Expand Up @@ -66,7 +78,7 @@ pub fn run(c: &mut Criterion) {
VmBench::new(op::mcl(0x10, 0x11)).with_prepare_script(vec![
op::movi(0x11, *i),
op::aloc(0x11),
op::addi(0x10, RegId::HP, 1),
op::move_(0x10, RegId::HP),
]),
);
}
Expand All @@ -81,7 +93,7 @@ pub fn run(c: &mut Criterion) {
VmBench::new(op::mcli(0x10, *i)).with_prepare_script(vec![
op::movi(0x11, *i),
op::aloc(0x11),
op::addi(0x10, RegId::HP, 1),
op::move_(0x10, RegId::HP),
]),
);
}
Expand All @@ -96,7 +108,7 @@ pub fn run(c: &mut Criterion) {
VmBench::new(op::mcp(0x10, RegId::ZERO, 0x11)).with_prepare_script(vec![
op::movi(0x11, *i),
op::aloc(0x11),
op::addi(0x10, RegId::HP, 1),
op::move_(0x10, RegId::HP),
]),
);
}
Expand All @@ -108,21 +120,23 @@ pub fn run(c: &mut Criterion) {
VmBench::new(op::mcpi(0x10, RegId::ZERO, 4000)).with_prepare_script(vec![
op::movi(0x11, 4000),
op::aloc(0x11),
op::addi(0x10, RegId::HP, 1),
op::move_(0x10, RegId::HP),
]),
);

let mut mem_meq = c.benchmark_group("meq");
for i in &linear {
mem_meq.throughput(Throughput::Bytes(*i as u64));

let mut prepare_script = vec![op::movi(0x11, 0)];
prepare_script.extend(set_full_word(0x12, (i * 3) as u64));
prepare_script.extend(set_full_word(0x13, (*i) as u64));

run_group_ref(
&mut mem_meq,
format!("{i}"),
VmBench::new(op::meq(0x10, 0x11, 0x12, 0x13)).with_prepare_script(vec![
op::movi(0x11, 0),
op::movi(0x12, i * 3),
op::movi(0x13, *i),
]),
VmBench::new(op::meq(0x10, 0x11, 0x12, 0x13))
.with_prepare_script(prepare_script),
);
}
mem_meq.finish();
Expand Down
5 changes: 2 additions & 3 deletions crates/fuel-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1952,9 +1952,8 @@ mod tests {
// Allocate 32 bytes on the heap.
op::aloc(0x11),
// Store the pointer to the beginning of the free memory into
// register `0x10`. It requires shifting of `RegId::HP` by 1 to point
// on the free memory.
op::addi(0x10, RegId::HP, 0),
// register `0x10`.
op::move_(0x10, RegId::HP),
// Store `config_coinbase` `Address` into MEM[$0x10; 32].
op::cb(0x10),
// Store the pointer on the beginning of script data into register `0x12`.
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async fn can_get_message_proof() {
// Set the location in memory to write the bytes to.
op::movi(0x11, 100),
op::aloc(0x11),
op::addi(0x11, RegId::HP, 1),
op::move_(0x11, RegId::HP),
op::movi(0x13, 2),
// Write read to 0x11.
// Write status to 0x30.
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,12 @@ async fn can_get_message_proof() {
// of the message recipient.
op::addi(0x10, 0x10, starting_offset),
];
contract.extend(args.iter().enumerate().flat_map(|(index, arg)| {
contract.extend(args.iter().flat_map(|arg| {
[
// Pointer to the message in memory
op::addi(0x11, 0x10, 32),
// The length of the message data in memory.
op::movi(0x11, arg.message_data.len() as u32),
// The index of the of the output message in the transactions outputs.
op::movi(0x12, (index + 1) as u32),
op::movi(0x12, arg.message_data.len() as u32),
// The amount to send in coins.
op::movi(0x13, amount),
// Send the message output.
Expand Down