Commit graph

3 commits

Author SHA1 Message Date
Igor Rončević
46e83a6fbe
Add --perf option to test to collect and diff performance data (#7459)
Some checks are pending
CI / build-sway-lib-std (push) Waiting to run
CI / forc-fmt-check-sway-lib-std (push) Waiting to run
CI / forc-fmt-check-sway-examples (push) Waiting to run
CI / forc-fmt-check-panic (push) Waiting to run
CI / check-sdk-harness-test-suite-compatibility (push) Waiting to run
CI / cargo-toml-fmt-check (push) Waiting to run
CI / cargo-fmt-check (push) Waiting to run
CI / cargo-run-e2e-test (push) Blocked by required conditions
CI / cargo-test-lib-std (push) Waiting to run
CI / forc-pkg-fuels-deps-check (push) Waiting to run
CI / check-forc-manifest-version (push) Waiting to run
CI / get-fuel-core-version (push) Waiting to run
CI / build-sway-examples (push) Waiting to run
CI / build-reference-examples (push) Waiting to run
CI / build-mdbook (push) Waiting to run
CI / build-forc-doc-sway-lib-std (push) Waiting to run
CI / build-forc-test-project (push) Waiting to run
CI / cargo-build-workspace (push) Waiting to run
CI / cargo-clippy (push) Waiting to run
CI / cargo-run-e2e-test-release (push) Blocked by required conditions
CI / forc-run-benchmarks (push) Waiting to run
CI / forc-unit-tests (push) Waiting to run
CI / Build and test various forc tools (push) Blocked by required conditions
CI / cargo-unused-deps-check (push) Waiting to run
CI / notify-slack-on-failure (push) Blocked by required conditions
CI / pre-publish-check (push) Waiting to run
CI / publish (push) Blocked by required conditions
CI / publish-sway-lib-std (push) Blocked by required conditions
CI / Build and upload forc binaries to release (push) Blocked by required conditions
github pages / deploy (push) Waiting to run
## Description

This PR:
- Adds `--perf` and `--perf-only` options to `test` to collect gas
usages and bytecode sizes, and to run only the tests that actually
produce those performance data, respectively.
- Adds `[performance]` recipes to `justfile` that fully automate a
workflow for collecting and comparing performance data of the compiler
output.

`--perf` flag instructs `test` to collect performance data from tests of
categories `compile`, `run`, and `unit_tests_pass`. Collected gas usages
and bytecode sizes are written to files named
`<timestamp>-<category>-<build profile>-<branch>.csv`. E.g.:
`1020165605-e2e-bytecode-sizes-release-master.csv`.

When running tests in parallel (default option), performance data of
each individual `test --exact <test_toml_path>` process is written to a
piped stdout in JSON format. The main `test` process collects those JSON
outputs from all spanned processes.

The usual workflow of collecting and comparing performance data between
the `master` and feature branch is supported by the following `just`
recipes:

```console
[performance]
perf-e2e filter=''                    # collect gas usages and bytecode sizes from E2E tests [alias: pe2e]
perf-in-lang filter=''                # collect gas usages from in-language tests [alias: pil]
perf-all filter=''                    # collect gas usages and bytecode sizes from all tests (E2E and in-language) [alias: pa]
perf-diff before after format='md'    # generate performance diff between two CSV files [alias: pd]
perf-diff-latest format='md'          # generate performance diffs between the latest two CSV files per testing category [alias: pdl]
perf-snapshot-historical path open='' # collect historic gas usages from a snapshot test that has a `forc test` output [alias: psh]
perf-list                             # list all performance files (*gas-usages-*.* and *bytecode-sizes-*.*) [alias: pl]
perf-remove                           # remove all performance files (*gas-usages-*.* and *bytecode-sizes-*.*) [alias: pr]
```

To obtain the performance comparison it is enough to run:

```console
just pa   // `just perf-all`. On `master` to get the baseline.
just pa   // `just perf-all`. On the feature branch to get the improved data.
just pdl  // `just perf-diff-latest`. To get the diff of the last two collected performance data sets.
```
The `just` recipes should be executed from the root of the Sway
repository.

Aside from `--perf` writing to predefined files, all other parts of the
workflow are `just` recipes and can potentially be tailored to any other
workflow.

Adding support for collecting gas usages and bytecode sizes from other
tests like (snapshot, in-language, SDK harness) will be added in follow
up PRs.

## Checklist

- [ ] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2025-10-21 18:41:35 +04:00
Daniel Frederico Lins Leite
4e16bedab2
Improve Contract Call by not encoding fuelvm protocol args (#7447)
Some checks are pending
CI / forc-fmt-check-panic (push) Waiting to run
CI / check-forc-manifest-version (push) Waiting to run
CI / get-fuel-core-version (push) Waiting to run
CI / build-sway-lib-std (push) Waiting to run
CI / build-sway-examples (push) Waiting to run
CI / forc-fmt-check-sway-lib-std (push) Waiting to run
CI / check-sdk-harness-test-suite-compatibility (push) Waiting to run
CI / build-mdbook (push) Waiting to run
CI / build-forc-doc-sway-lib-std (push) Waiting to run
CI / build-forc-test-project (push) Waiting to run
CI / cargo-build-workspace (push) Waiting to run
CI / Build and test various forc tools (push) Blocked by required conditions
CI / cargo-unused-deps-check (push) Waiting to run
CI / pre-publish-check (push) Waiting to run
CI / publish (push) Blocked by required conditions
CI / publish-sway-lib-std (push) Blocked by required conditions
CI / Build and upload forc binaries to release (push) Blocked by required conditions
github pages / deploy (push) Waiting to run
CI / build-reference-examples (push) Waiting to run
CI / forc-fmt-check-sway-examples (push) Waiting to run
CI / cargo-clippy (push) Waiting to run
CI / cargo-toml-fmt-check (push) Waiting to run
CI / cargo-fmt-check (push) Waiting to run
CI / cargo-run-e2e-test (push) Blocked by required conditions
CI / cargo-run-e2e-test-release (push) Blocked by required conditions
CI / cargo-test-lib-std (push) Waiting to run
CI / forc-run-benchmarks (push) Waiting to run
CI / forc-unit-tests (push) Waiting to run
CI / forc-pkg-fuels-deps-check (push) Waiting to run
CI / notify-slack-on-failure (push) Blocked by required conditions
## Description

This is an optimization of contract calls on top of
https://github.com/FuelLabs/sway/pull/7440.

```csv
const_of_contract_call::cost_of_in_array_0,1976,1285
const_of_contract_call::cost_of_in_array_1,3164,1779
const_of_contract_call::cost_of_in_array_16,5096,4753
const_of_contract_call::cost_of_in_array_32,8421,8079
const_of_contract_call::cost_of_in_array_64,60382,14545
const_of_contract_call::cost_of_in_array_8,4724,4382
const_of_contract_call::cost_of_in_b256,2491,2147
const_of_contract_call::cost_of_in_bool,2627,2279
const_of_contract_call::cost_of_in_str_0,3043,2697
const_of_contract_call::cost_of_in_str_1,3345,2998
const_of_contract_call::cost_of_in_str_16,3374,3030
const_of_contract_call::cost_of_in_str_32,3572,3227
const_of_contract_call::cost_of_in_str_8,3768,3421
const_of_contract_call::cost_of_in_tuple_0,3822,3479
const_of_contract_call::cost_of_in_tuple_1,4392,4050
const_of_contract_call::cost_of_in_tuple_2,4761,4418
const_of_contract_call::cost_of_in_tuple_3,5104,4761
const_of_contract_call::cost_of_in_tuple_4,5468,5126
const_of_contract_call::cost_of_in_u16,4493,4141
const_of_contract_call::cost_of_in_u256,4777,4433
const_of_contract_call::cost_of_in_u32,4926,4582
const_of_contract_call::cost_of_in_u64,4934,4589
const_of_contract_call::cost_of_in_u8,4874,4526
const_of_contract_call::in_enum_u64,3186,2843
const_of_contract_call::in_enum_u64_u64,3061,2718
const_of_contract_call::in_enum_u64_u64_u64,3173,2830
const_of_contract_call::in_struct_u64,3635,3293
const_of_contract_call::in_struct_u64_u64,3897,3554
const_of_contract_call::in_struct_u64_u64_u64,4156,3813
const_of_contract_call::isolated_cost_of_in_array_0,956,956
const_of_contract_call::isolated_cost_of_in_array_1,1515,1185
const_of_contract_call::isolated_cost_of_in_array_16,3955,3266
const_of_contract_call::isolated_cost_of_in_array_32,6544,5471
const_of_contract_call::isolated_cost_of_in_array_64,9914,9914
const_of_contract_call::isolated_cost_of_in_array_8,3225,2728
const_of_contract_call::isolated_cost_of_in_b256,1462,1120
const_of_contract_call::isolated_cost_of_in_bool,1358,1047
const_of_contract_call::isolated_cost_of_in_str_0,1451,1140
const_of_contract_call::isolated_cost_of_in_str_1,1547,1237
const_of_contract_call::isolated_cost_of_in_str_16,1552,1241
const_of_contract_call::isolated_cost_of_in_str_32,1553,1242
const_of_contract_call::isolated_cost_of_in_str_8,1551,1241
const_of_contract_call::isolated_cost_of_in_tuple_0,820,820
const_of_contract_call::isolated_cost_of_in_tuple_1,1412,1090
const_of_contract_call::isolated_cost_of_in_tuple_2,1615,1304
const_of_contract_call::isolated_cost_of_in_tuple_3,1766,1455
const_of_contract_call::isolated_cost_of_in_tuple_4,1916,1605
const_of_contract_call::isolated_cost_of_in_u16,1428,1117
const_of_contract_call::isolated_cost_of_in_u256,1431,1120
const_of_contract_call::isolated_cost_of_in_u32,1554,1243
const_of_contract_call::isolated_cost_of_in_u64,1336,1025
const_of_contract_call::isolated_cost_of_in_u8,1352,1041
```

## Checklist

- [x] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2025-10-20 17:24:58 +00:00
Daniel Frederico Lins Leite
5896b4cac2
Cost of contract calls snapshot tests (#7440)
Some checks failed
CI / check-dependency-version-formats (push) Has been cancelled
CI / get-fuel-core-version (push) Has been cancelled
CI / build-sway-lib-std (push) Has been cancelled
CI / forc-fmt-check-sway-examples (push) Has been cancelled
Codspeed Benchmarks / benchmarks (push) Has been cancelled
CI / check-forc-manifest-version (push) Has been cancelled
CI / forc-fmt-check-panic (push) Has been cancelled
CI / check-sdk-harness-test-suite-compatibility (push) Has been cancelled
CI / build-mdbook (push) Has been cancelled
CI / build-forc-doc-sway-lib-std (push) Has been cancelled
CI / build-forc-test-project (push) Has been cancelled
CI / cargo-build-workspace (push) Has been cancelled
CI / cargo-clippy (push) Has been cancelled
CI / cargo-toml-fmt-check (push) Has been cancelled
CI / cargo-fmt-check (push) Has been cancelled
CI / cargo-test-lib-std (push) Has been cancelled
CI / forc-run-benchmarks (push) Has been cancelled
CI / forc-unit-tests (push) Has been cancelled
CI / forc-pkg-fuels-deps-check (push) Has been cancelled
CI / cargo-unused-deps-check (push) Has been cancelled
CI / pre-publish-check (push) Has been cancelled
github pages / deploy (push) Has been cancelled
CI / Build and upload forc binaries to release (push) Has been cancelled
CI / verifications-complete (push) Has been cancelled
CI / cargo-run-e2e-test (push) Has been cancelled
CI / cargo-run-e2e-test-release (push) Has been cancelled
CI / Build and test various forc tools (push) Has been cancelled
CI / notify-slack-on-failure (push) Has been cancelled
CI / publish (push) Has been cancelled
CI / publish-sway-lib-std (push) Has been cancelled
## Description

This PR is a prequel for https://github.com/FuelLabs/sway/pull/7419.
It will set the baseline, which future PRs need to improve.

Apart from that it also:
1 - Fix a problem with `SubtsType` for `TyConstantDecl`;
2 - Introduce a new way to write snapshot tests. Now the test source
code can have "blocks"

```
    /* START BOOL */
    fn in_bool(v: bool) -> bool;
    /* END BOOL */
```

These blocks can be manipulated from inside the `snapshot.toml`. In this
case, the `toml` is:

```
cmds = [
    "forc test --path {root} --release --experimental const_generics",
    { repeat = "for-each-block", cmds = [
        "forc test --path {root} --release --experimental const_generics"
    ] }
]
```

Which repeats the inner `forc test` for each block, removing all others.
That allows me to check the cost of the contract method selection
algorithm for each contract method.

For example, `cost_of_in_array_64` with all other contract methods costs
`60382`, but alone it only costs `58218`, which means that around 2000
was "wasted" in the contract method selection.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2025-10-16 14:41:51 +00:00