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

Use DependentCost for aloc opcode #1934

Merged
merged 39 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
81dc78a
Reuse VM memory across executions
Dentosal May 8, 2024
42105ce
Add changelog entry
Dentosal May 8, 2024
e14cf0b
Merge branch 'master' into dento/reuse-vm-memory
Dentosal May 8, 2024
5caec42
Switch to a unified pool instead of per-thread one
Dentosal May 9, 2024
6340785
Move VmPool to fuel-vm, use it for predicates as well
Dentosal May 10, 2024
22fa926
Cleanup
Dentosal May 10, 2024
8c276e9
Cleanup
Dentosal May 10, 2024
0b11719
Fix benches
Dentosal May 10, 2024
4c6f29b
Add changes from the latest fuel-vm side update
Dentosal May 13, 2024
22f3ba4
Match fuel-vm changes
Dentosal May 14, 2024
4f9340c
Merge branch 'master' into dento/reuse-vm-memory
Dentosal May 14, 2024
57d2049
cargo sort
Dentosal May 14, 2024
0e41a28
Merge branch 'refs/heads/master' into dento/reuse-vm-memory
xgreenx Jun 3, 2024
a762483
Use `fuel-vm 0.51.0`
xgreenx Jun 3, 2024
131a91e
Merge branch 'master' into dento/reuse-vm-memory
xgreenx Jun 3, 2024
98c7495
Make clippy happy
xgreenx Jun 3, 2024
395077b
Fix CI
xgreenx Jun 3, 2024
36fa8be
Fix CI
xgreenx Jun 3, 2024
3baea26
Fix CI
xgreenx Jun 3, 2024
b13578f
Fixed VM initialization benchmark
xgreenx Jun 3, 2024
eb65aba
Merge branch 'master' into dento/reuse-vm-memory
xgreenx Jun 3, 2024
5196bab
Use release 0.51
xgreenx Jun 3, 2024
2e4bc5b
Merge remote-tracking branch 'origin/dento/reuse-vm-memory' into dent…
xgreenx Jun 3, 2024
c2034bb
Make clippy happy
xgreenx Jun 3, 2024
ec2a65b
Fixed becnhmark for aloc opcode
xgreenx Jun 3, 2024
fc15915
Fixed becnhmark for aloc opcode
xgreenx Jun 3, 2024
6000f11
Not include cloning of memory into the benchamrk results
xgreenx Jun 3, 2024
56915e7
Return back old benchmark
xgreenx Jun 3, 2024
564fec0
Make `aloc` depdedent
xgreenx Jun 3, 2024
a719693
Remove warnings
xgreenx Jun 3, 2024
c8248b9
Use bigger values
xgreenx Jun 3, 2024
38f57f9
Use bigger values
xgreenx Jun 3, 2024
de2ec13
Use V2 gas costs
xgreenx Jun 4, 2024
7ac5fa5
Merge branch 'refs/heads/master' into feature/benchmarks-alloc
xgreenx Jun 5, 2024
62e6f24
Updated gas cost to match the current version of the executor
xgreenx Jun 5, 2024
ae90adf
Merge branch 'refs/heads/master' into feature/benchmarks-alloc
xgreenx Jun 5, 2024
cbd73d9
Updated CHANGELOG.md
xgreenx Jun 5, 2024
13fe891
Fixed test
xgreenx Jun 5, 2024
703033a
Merge branch 'master' into feature/benchmarks-alloc
MitchTurner Jun 6, 2024
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
11 changes: 5 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Changed
- [#1934](https://github.com/FuelLabs/fuel-core/pull/1934): Updated benchmark for the `aloc` opcode to be `DependentCost`. Updated `vm_initialization` benchmark to exclude growing of memory(It is handled by VM reuse).
- [#1916](https://github.com/FuelLabs/fuel-core/pull/1916): Speed up synchronisation of the blocks for the `fuel-core-sync` service.
- [#1888](https://github.com/FuelLabs/fuel-core/pull/1888): optimization: Reuse VM memory across executions.

#### Breaking

- [#1934](https://github.com/FuelLabs/fuel-core/pull/1934): Changed `GasCosts` endpoint to return `DependentCost` for the `aloc` opcode via `alocDependentCost`.
- [#1934](https://github.com/FuelLabs/fuel-core/pull/1934): Updated default gas costs for the local testnet configuration. All opcodes became cheaper.
- [#1924](https://github.com/FuelLabs/fuel-core/pull/1924): `dry_run_opt` has new `gas_price: Option<u64>` argument
- [#1888](https://github.com/FuelLabs/fuel-core/pull/1888): Upgraded `fuel-vm` to `0.51.0`. See [release](https://github.com/FuelLabs/fuel-vm/releases/tag/v0.51.0) for more information.

### Added
- [#1929](https://github.com/FuelLabs/fuel-core/pull/1929): Added support of customization of the state transition version in the `ChainConfig`.

### Removed
- [#1913](https://github.com/FuelLabs/fuel-core/pull/1913): Removed dead code from the project.

### Changed
- [#1888](https://github.com/FuelLabs/fuel-core/pull/1888): optimization: Reuse VM memory across executions.

#### Breaking
- [#1888](https://github.com/FuelLabs/fuel-core/pull/1888): Upgraded `fuel-vm` to `0.51.0`. See [release](https://github.com/FuelLabs/fuel-vm/releases/tag/v0.51.0) for more information.

### Fixed
- [#1921](https://github.com/FuelLabs/fuel-core/pull/1921): Fixed unstable `gossipsub_broadcast_tx_with_accept` test.
- [#1915](https://github.com/FuelLabs/fuel-core/pull/1915): Fixed reconnection issue in the dev cluster with AWS cluster.
Expand Down
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.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fuel-core-wasm-executor = { version = "0.27.0", path = "./crates/services/upgrad
fuel-core-xtask = { version = "0.0.0", path = "./xtask" }

# Fuel dependencies
fuel-vm-private = { version = "0.51.0", package = "fuel-vm", default-features = false }
fuel-vm-private = { version = "0.52.0", package = "fuel-vm", default-features = false }
Copy link
Member

Choose a reason for hiding this comment

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

The changelog says your updating to 0.51.0, not 0.52.0.

Copy link
Member

Choose a reason for hiding this comment

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

[#1888](https://github.com/FuelLabs/fuel-core/pull/1888): Upgraded `fuel-vm` to `0.51.0`. See [release](https://github.com/FuelLabs/fuel-vm/releases/tag/v0.51.0) for more information.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The changelog related for 0.51.0 is from another PR, I just grouped everything together=)

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 we are being inconsistent about when we note these things, but I don't know that it matters


# Common dependencies
anyhow = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion benches/benches-outputs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use fuel_core_types::fuel_tx::{
consensus_parameters::gas::GasCostsValuesV1,
consensus_parameters::gas::GasCostsValuesV2,
DependentCost,
GasCostsValues,
};
Expand Down
22 changes: 21 additions & 1 deletion benches/benches/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

use core::iter::successors;
use ethnum::U256;
use fuel_core_types::{
Expand Down Expand Up @@ -80,7 +82,6 @@ pub fn set_full_word(r: RegisterId, v: Word) -> Vec<Instruction> {
const BENCH_RECEIPTS: usize = (u16::MAX - 4) as usize;

/// Testing receipt context
#[allow(dead_code)] // Unsure why this is needed, as the code is used
pub fn make_receipts(rng: &mut StdRng) -> ReceiptsCtx {
let mut ctx = ReceiptsCtx::default();
for _ in 0..BENCH_RECEIPTS {
Expand All @@ -97,3 +98,22 @@ pub fn make_receipts(rng: &mut StdRng) -> ReceiptsCtx {
}
ctx
}

const LAST_VALUE: u64 = 100_000;

pub fn linear_short() -> Vec<u64> {
let mut linear_short = vec![1, 10, 100, 1000, 10_000];
linear_short.push(LAST_VALUE);
linear_short
}

pub fn linear() -> Vec<u64> {
let mut linear: Vec<u64> = vec![1, 10, 100, 1000, 10_000];
let mut l = successors(Some(LAST_VALUE as f64), |n| Some(n / 1.5))
.take(5)
.map(|f| f as u64)
.collect::<Vec<_>>();
l.sort_unstable();
linear.extend(l);
linear
}
62 changes: 5 additions & 57 deletions benches/benches/vm_initialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use criterion::{
Criterion,
Throughput,
};
use fuel_core_storage::InterpreterStorage;
use fuel_core_types::{
fuel_asm::{
op,
Expand All @@ -23,17 +22,8 @@ use fuel_core_types::{
checked_transaction::{
Checked,
IntoChecked,
Ready,
},
constraints::reg_key::{
Reg,
RegMut,
},
consts::VM_MAX_RAM,
interpreter::{
MemoryInstance,
NotSupportedEcal,
},
interpreter::NotSupportedEcal,
Interpreter,
},
};
Expand Down Expand Up @@ -110,56 +100,14 @@ pub fn vm_initialization(c: &mut Criterion) {
group.throughput(Throughput::Bytes(tx_size as u64));
group.bench_function(name, |b| {
b.iter(|| {
unoptimized_vm_initialization_with_allocating_full_range_of_memory(
&mut vm, &tx,
#[allow(clippy::unit_arg)]
black_box(
Comment on lines +103 to +104
Copy link
Member

Choose a reason for hiding this comment

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

Does this black_box actually do anything?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removing black_box improves speed
image

vm.init_script(tx.clone())
.expect("Should be able to execute transaction"),
);
})
});
}

group.finish();
}

#[allow(clippy::unit_arg)]
fn unoptimized_vm_initialization_with_allocating_full_range_of_memory<S>(
vm: &mut Interpreter<MemoryInstance, S, Script>,
ready_tx: &Ready<Script>,
) where
S: InterpreterStorage,
{
black_box(initialize_vm_with_allocated_full_range_of_memory(
black_box(ready_tx.clone()),
vm,
));
}

fn initialize_vm_with_allocated_full_range_of_memory<S>(
ready_tx: Ready<Script>,
vm: &mut Interpreter<MemoryInstance, S, Script>,
) where
S: InterpreterStorage,
{
vm.init_script(ready_tx)
.expect("Should be able to execute transaction");

const POWER_OF_TWO_OF_HALF_VM: u64 = 25;
const VM_MEM_HALF: u64 = 1 << POWER_OF_TWO_OF_HALF_VM;
assert_eq!(VM_MEM_HALF, VM_MAX_RAM / 2);
let mut hp = VM_MAX_RAM;

for i in 0..=POWER_OF_TWO_OF_HALF_VM {
let stack = 1 << i;
let heap = stack / 2;

vm.memory_mut()
.grow_stack(stack)
.expect("Should be able to grow stack");
vm.memory_mut()
.grow_heap_by(Reg::new(&0), RegMut::new(&mut hp), heap)
.expect("Should be able to grow heap");
}

vm.memory_mut()
.grow_heap_by(Reg::new(&0), RegMut::new(&mut hp), VM_MEM_HALF)
.expect("Should be able to grow heap");
}
34 changes: 27 additions & 7 deletions benches/benches/vm_set/alu.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
use super::run_group_ref;

use criterion::Criterion;
use criterion::{
Criterion,
Throughput,
};
use ethnum::U256;
use fuel_core_benches::*;
use fuel_core_types::fuel_asm::*;

use crate::utils::{
linear_short,
set_full_word,
};
use fuel_core_types::fuel_asm::wideint::{
CompareArgs,
CompareMode,
Expand All @@ -20,6 +27,8 @@ use super::utils::{
};

pub fn run(c: &mut Criterion) {
let linear_short = linear_short();

run_group_ref(
&mut c.benchmark_group("add"),
"add",
Expand All @@ -34,12 +43,23 @@ pub fn run(c: &mut Criterion) {
.with_prepare_script(vec![op::movi(0x11, 100000)]),
);

run_group_ref(
&mut c.benchmark_group("aloc"),
"aloc",
VmBench::new(op::aloc(0x10))
.with_prepare_script(vec![op::movi(0x10, (1 << 18) - 1)]),
);
// aloc
{
let mut aloc = c.benchmark_group("aloc");

let mut aloc_linear = linear_short.clone();
aloc_linear.push(1_000_000);
aloc_linear.push(10_000_000);
aloc_linear.push(30_000_000);
for i in aloc_linear {
let bench =
VmBench::new(op::aloc(0x10)).with_prepare_script(set_full_word(0x10, i));
aloc.throughput(Throughput::Bytes(i));
run_group_ref(&mut aloc, format!("{i}"), bench);
}

aloc.finish();
}

run_group_ref(
&mut c.benchmark_group("and"),
Expand Down
25 changes: 9 additions & 16 deletions benches/benches/vm_set/blockchain.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::{
iter::successors,
sync::Arc,
};
use std::sync::Arc;

use crate::utils::make_receipts;
use crate::utils::{
linear,
linear_short,
make_receipts,
};

use super::run_group_ref;

Expand Down Expand Up @@ -151,16 +152,8 @@ impl BenchDb {
pub fn run(c: &mut Criterion) {
let rng = &mut StdRng::seed_from_u64(2322u64);

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

let asset = AssetId::zeroed();
let contract: ContractId = VmBench::CONTRACT;
Expand Down Expand Up @@ -287,7 +280,7 @@ pub fn run(c: &mut Criterion) {
let mut call = c.benchmark_group("call");

for i in linear.clone() {
let mut code = vec![0u8; i as usize];
let mut code = vec![123u8; i as usize];

rng.fill_bytes(&mut code);

Expand Down
6 changes: 3 additions & 3 deletions benches/src/bin/collect.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::Parser;
use fuel_core_types::fuel_tx::{
consensus_parameters::gas::GasCostsValuesV1,
consensus_parameters::gas::GasCostsValuesV2,
ConsensusParameters,
GasCosts,
};
Expand Down Expand Up @@ -371,7 +371,7 @@ pub const GIT: &str = ""#,
r#"";"#,
r##"
pub fn default_gas_costs() -> GasCostsValues {
GasCostsValuesV1 {"##,
GasCostsValuesV2 {"##,
r##" }.into()
}
"##,
Expand Down Expand Up @@ -495,7 +495,7 @@ impl State {
)
}

fn to_gas_costs(&self) -> GasCostsValuesV1 {
fn to_gas_costs(&self) -> GasCostsValuesV2 {
serde_yaml::from_value(self.to_yaml()).unwrap()
}

Expand Down
Loading
Loading