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

Fixed benchmarks for the 0.25.3 #1870

Merged
merged 37 commits into from
Apr 30, 2024
Merged

Fixed benchmarks for the 0.25.3 #1870

merged 37 commits into from
Apr 30, 2024

Conversation

xgreenx
Copy link
Collaborator

@xgreenx xgreenx commented Apr 29, 2024

Closes #1807

The PR updates benchmarks to work properly with new VM rules and fixes the issue with non-optimal InMemoryTransaction behavior for the size_of_value method.

Because of the new VM rules: the memory that we are accessing should be initialized. The cfe opcode in the benchmarks expands the stack to allocate the memory that will later be used by the instruction that we are benchmarking.

Before requesting review

  • I have reviewed the code myself

@xgreenx xgreenx requested a review from a team April 29, 2024 11:03
@xgreenx xgreenx self-assigned this Apr 29, 2024
@xgreenx xgreenx marked this pull request as ready for review April 29, 2024 11:42
xgreenx and others added 4 commits April 29, 2024 18:48
# Conflicts:
#	bin/fuel-core/chainspec/dev-testnet/state_transition_bytecode.wasm
#	bin/fuel-core/chainspec/testnet/state_transition_bytecode.wasm
bvrooman
bvrooman previously approved these changes Apr 29, 2024
Copy link
Contributor

@bvrooman bvrooman left a comment

Choose a reason for hiding this comment

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

Just a small optional correct and question

CHANGELOG.md Outdated Show resolved Hide resolved
@@ -70,7 +70,7 @@ pub fn run(c: &mut Criterion) {
format!("{i}"),
VmBench::contract(rng, op::retd(RegId::ONE, 0x10))
.unwrap()
.with_post_call(vec![op::movi(0x10, *i)])
.with_post_call(vec![op::movi(0x10, *i), op::cfe(0x10)])
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand the significance of adding cfe here or why it uses these specific registers. Can you elaborate on why we need this change? Is this just to make sure our benchmarks account for the worst case scenario?

Copy link
Collaborator Author

@xgreenx xgreenx Apr 29, 2024

Choose a reason for hiding this comment

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

Because of the new VM rules: the memory that we are accessing should be initialized. The cfe opcode in the benchmarks expands the stack to allocate the memory that will later be used by the instruction that we are benchmarking.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I understand better. In this example, we have retd(RegId::ONE, 0x10), where we return the memory in the range from *ONE to *0x10. So we need to extend the call stack by the value pointed by 0x10.

Co-authored-by: Brandon Vrooman <[email protected]>
bvrooman
bvrooman previously approved these changes Apr 29, 2024
@@ -85,6 +87,9 @@ pub fn vm_initialization(c: &mut Criterion) {
if size as u64 > consensus_params.script_params().max_script_data_length() {
break
}
if 2 * size as u64 > consensus_params.tx_params().max_size() {
Copy link
Member

Choose a reason for hiding this comment

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

Can we put this into a helper with the name that explains why this should break? Same with the above break.

if `something_size_is_foo_bar_baz(size, consensus_params)` {
    break
}

It's not clear to me what the significance of size (size of what?) being half as big as the max tx size.


// Initialize the VM and require the allocation of the whole memory
// to charge for the worst possible case.
black_box({
Copy link
Member

Choose a reason for hiding this comment

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

I could say a the same for a lot of this. Can we move everthing in these curlies into some helper?

@@ -249,6 +283,31 @@ where
self.storage.get(key, column)
}
}

fn read(
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused. Did we not have implementations for these methods before on InMemoryTransaction?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We had a default implementation that was calling a get method which is less optimal in the case of RocksDB.

image

@xgreenx xgreenx requested review from MitchTurner, bvrooman and a team April 30, 2024 06:28
Comment on lines 104 to 110
let vm = black_box(
Interpreter::<_, Script, NotSupportedEcal>::with_memory_storage(),
);
let ready_tx = tx.clone().test_into_ready();
black_box(vm.init_script(ready_tx))
.expect("Should be able to execute transaction");

// Initialize the VM and require the allocation of the whole memory
// to charge for the worst possible case.
black_box(initialize_vm(black_box(tx.clone()), vm));
Copy link
Member

Choose a reason for hiding this comment

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

This is even more confusing from before. I'm not sure where the extra black_box came from either.

Can we just have a method that says what we want, and then hide the implementation behind it? We probably can get rid of the comment in that case too.

unoptimized_and_fully_saturated_vm or something like that. Then have the internal code create the vm and wrap the vm and the tx in black_box?

@xgreenx xgreenx requested review from MitchTurner and a team April 30, 2024 07:23
@xgreenx xgreenx enabled auto-merge (squash) April 30, 2024 07:26
@xgreenx xgreenx merged commit f12ee07 into master Apr 30, 2024
30 checks passed
@xgreenx xgreenx deleted the feature/benchmarks-0.25.2 branch April 30, 2024 07:33
@xgreenx xgreenx mentioned this pull request Apr 30, 2024
xgreenx added a commit that referenced this pull request Apr 30, 2024
## Version v0.26.0

### Fixed

#### Breaking

- [#1868](#1868): Include the
`event_inbox_root` in the header hash. Changed types of the
`transactions_count` to `u16` and `message_receipt_count` to `u32`
instead of `u64`. Updated the application hash root calculation to not
pad numbers.
- [#1866](#1866): Fixed a
runtime panic that occurred when restarting a node. The panic happens
when the relayer database is already populated, and the relayer attempts
an empty commit during start up. This invalid commit is removed in this
PR.
- [#1871](#1871): Fixed
`block` endpoint to return fetch the blocks from both databases after
regenesis.
- [#1856](#1856): Replaced
instances of `Union` with `Enum` for GraphQL definitions of
`ConsensusParametersVersion` and related types. This is needed because
`Union` does not support multiple `Version`s inside discriminants or
empty variants.
- [#1870](#1870): Fixed
benchmarks for the `0.25.3`.
- [#1870](#1870): Improves the
performance of getting the size of the contract from the
`InMemoryTransaction`.
- [#1851](#1851): Provided
migration capabilities (enabled addition of new column families) to
RocksDB instance.

### Added 

- [#1853](#1853): Added a test
case to verify the database's behavior when new columns are added to the
RocksDB database.
- [#1860](#1860): Regenesis
now preserves `FuelBlockIdsToHeights` off-chain table.

### Changed

- [#1847](#1847): Simplify the
validation interface to use `Block`. Remove `Validation` variant of
`ExecutionKind`.
- [#1832](#1832): Snapshot
generation can be cancelled. Progress is also reported.
- [#1837](#1837): Refactor the
executor and separate validation from the other use cases

## What's Changed
* Weekly `cargo update` by @github-actions in
#1850
* Refactor/separate validation from other executions by @MitchTurner in
#1837
* fix: Use `Enum` for `ConsensusParametersVersion` and related types by
@bvrooman in #1856
* feat: snapshot generation graceful shutdown by @segfault-magnet in
#1832
* regenesis: migrate FuelBlockIdsToHeights by @Dentosal in
#1860
* Weekly `cargo update` by @github-actions in
#1869
* Refactor/Simplify validation logic by @MitchTurner in
#1847
* Fixed `block` endpoint to return fetch the blocks from both databases
after regenesis by @xgreenx in
#1871
* Add Eq and Partial Eq to tx response and status by @MujkicA in
#1872
* test: restart with relayer data by @bvrooman in
#1866
* Fix `BlockHeader` hash by @MitchTurner in
#1868
* Added a test for the case of adding new columns into the existing
RocksDB database by @xgreenx in
#1853
* Fixed benchmarks for the `0.25.3` by @xgreenx in
#1870


**Full Changelog**:
v0.25.3...v0.26.0
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.

Update VM initialisation gas cost benchmark
4 participants