mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-10-21 03:06:17 +00:00
# Description
Compilation times for resolc were significantly slower than solc when:
* Multiple files were included in the JSON input file via
`--standard-json`
* And none of the files requested code generation
* (If only a subset of files requested code generation, both resolc and
solc were very slow)
Reason:
* Resolc unconditionally generated bytecode for all contracts, even if
not requested.
* When compiling to PolkaVM bytecode, we need to pass additional flags
(e.g. `irOptimized`) to solc. If these flags were not explicitly
requested, resolc also added these to the requested output since PolkaVM
bytecode was always generated.
## Breaking Changes
The following changes are breaking, but fix the semantics to match its
intended behavior:
* Compiling with `--standard-json` now compiles to PolkaVM bytecode
***only*** for the contracts explicitly requested in the
`outputSelection`.
* Compiling with `--standard-json` now outputs ***only*** the explicitly
requested output (e.g. `evm.assembly`, `evm.bytecode`, `ast`, etc.).
```jsonc
// Example:
{
"settings": {
// ...
"outputSelection": {
"src/common/GasService.sol": {
// Contracts in this file will generate bytecode.
// Only these fields of the JSON output selection will be in the `contracts` output.
"*": ["abi", "evm.methodIdentifiers", "metadata", "evm.bytecode"],
// Only this field of the JSON output selection will be in the `sources` output.
"": ["ast"]
},
"src/common/Gateway.sol": {
// No contracts in this file will generate bytecode.
"*": ["abi", "evm.methodIdentifiers", "metadata"],
// No `ast` will be in the `sources` output (only the automatically added `id`,
// similar to solc as this is not a configurable output selection).
"": []
},
}
}
}
```
## Performance Improvements
When e.g. the standard JSON input file includes multiple files and
requests output for every contract as per this setting:
```jsonc
{
"settings": {
// ...
"optimizer": { "enabled": true, "runs": 1 },
"viaIR": true,
"outputSelection": {
"src/common/GasService.sol": {
"*": ["abi", "evm.methodIdentifiers", "metadata", "evm.bytecode"],
},
// Rest of files..
}
}
}
```
The differences in compilation times depending on whether `evm.bytecode`
is selected in every file, one file, or no files can be seen below:
| Solc Optimizer (runs=1) | ViaIR | Request `abi`,
`evm.methodIdentifiers`, `metadata` | Request `evm.bytecode` | resolc
before | resolc after | solc v0.8.33 |
|:-----------------------:|:-----:|:---------:|:---------:|:-------------:|:------------:|:----------:|
| ✅ | ✅ | All files | All files | `~14.5s` | `~14.5s` | `~13.5s` |
| ✅ | ✅ | All files | One file | `~14.5s` | `~450ms` | `~13.5s` |
| ✅ | ✅ | All files | No files | `~14.5s` | `~390ms` | `~350ms` |
**Observations:**
* `resolc before` is roughly the same no matter the request
* This is due to unconditionally generating bytecode
* When not requesting bytecode for any contracts:
* `resolc after` now compiles in ~390ms (vs ~14.5s), similar to `solc`
* Neither `solc` nor `resolc after` generates bytecode when none of the
contracts request it
* When requesting bytecode for all contracts in _only one_ file:
* `resolc after` now compiles in ~450ms (vs ~14.5s)
* `solc` still compiles in the same time as when requesting bytecode for
all contracts in all files
* This is something they have tried to improve (see
[Solidity#15373](https://github.com/argotorg/solidity/issues/15373) and
[Solidity#15615](https://github.com/argotorg/solidity/issues/15615)),
and the intended behavior seems to now be that bytecode should only be
generated when explicitly requested for each contract.
* Even though PRs have merged to try to fix it, their issue seems to
persist as of v0.8.33.
# Open Questions
* Foundry:
* [x] Pruning of the AST:
* Just saw [this past
commit](https://github.com/paritytech/revive/pull/385) to not prune the
AST for Foundry compatibility.
* Can Foundry not explicitly request `"": "ast"`?
* **Answer:**
* Pruning the AST when not requested should be fine, as long as Foundry
explicitly requests it when needed.
* Will be tested by Foundry maintainer.
# Review Notes
Changes in `docs/` (~25 files) can be skipped as they are automatically
updated after adding content to `book/` and rebuilding it.
# Resolved Issues
Closes #326
---------
Co-authored-by: xermicus <cyrill@parity.io>
166 lines
4.5 KiB
YAML
166 lines
4.5 KiB
YAML
name: Benchmark
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
ref_before:
|
|
description: "Branch, tag, or SHA before changes"
|
|
default: "main"
|
|
type: string
|
|
required: true
|
|
ref_after:
|
|
description: "Branch, tag, or SHA after changes"
|
|
type: string
|
|
required: true
|
|
pr_number:
|
|
description: "PR number (for posting the result as a comment)"
|
|
type: number
|
|
required: false
|
|
|
|
# Cancels in-progress runs for runs comparing the same refs if the workflow is re-triggered.
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ inputs.ref_before }}-${{ inputs.ref_after }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
benchmark:
|
|
runs-on: parity-large
|
|
permissions:
|
|
pull-requests: write
|
|
steps:
|
|
- name: Checkout Commit Before Changes
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ inputs.ref_before }}
|
|
|
|
- name: Set Up Rust Toolchain
|
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
with:
|
|
# Without this it will override our rust flags.
|
|
rustflags: ""
|
|
|
|
- name: Install Node.js
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version: "lts/*"
|
|
|
|
- name: Install Benchmarking Tools
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y build-essential
|
|
cargo install critcmp
|
|
|
|
- name: Install Solc
|
|
uses: ./.github/actions/get-solc
|
|
|
|
- name: Download LLVM
|
|
uses: ./.github/actions/get-llvm
|
|
with:
|
|
target: x86_64-unknown-linux-gnu
|
|
|
|
- name: Set LLVM Environment Variables
|
|
run: |
|
|
echo "LLVM_SYS_181_PREFIX=$(pwd)/llvm-x86_64-unknown-linux-gnu" >> $GITHUB_ENV
|
|
|
|
- name: Build resolc
|
|
run: |
|
|
make install
|
|
|
|
- name: Run Benchmarks on Commit Before Changes
|
|
run: |
|
|
cargo bench --package resolc --bench compile -- --save-baseline resolc_before
|
|
cargo bench --package revive-benchmarks --bench parse -- --save-baseline yul_parse_before
|
|
cargo bench --package revive-benchmarks --bench lower -- --save-baseline yul_lower_before
|
|
timeout-minutes: 40
|
|
|
|
- name: Checkout Commit After Changes
|
|
run: |
|
|
git fetch origin ${{ inputs.ref_after }}
|
|
git checkout -f ${{ inputs.ref_after }}
|
|
|
|
- name: Install Solc
|
|
uses: ./.github/actions/get-solc
|
|
|
|
- name: Download LLVM
|
|
uses: ./.github/actions/get-llvm
|
|
with:
|
|
target: x86_64-unknown-linux-gnu
|
|
|
|
- name: Build resolc
|
|
run: |
|
|
make install
|
|
|
|
- name: Run Benchmarks on Commit After Changes
|
|
run: |
|
|
cargo bench --package resolc --bench compile -- --save-baseline resolc_changes
|
|
cargo bench --package revive-benchmarks --bench parse -- --save-baseline yul_parse_changes
|
|
cargo bench --package revive-benchmarks --bench lower -- --save-baseline yul_lower_changes
|
|
timeout-minutes: 40
|
|
|
|
- name: Compare Benchmarks
|
|
run: |
|
|
critcmp resolc_before resolc_changes > benchmarks_resolc
|
|
critcmp yul_parse_before yul_parse_changes > benchmarks_yul_parse
|
|
critcmp yul_lower_before yul_lower_changes > benchmarks_yul_lower
|
|
|
|
- name: Create Report
|
|
env:
|
|
REF_BEFORE: ${{ inputs.ref_before }}
|
|
REF_AFTER: ${{ inputs.ref_after }}
|
|
run: |
|
|
cat > BENCHMARK_REPORT.md << EOF
|
|
# Benchmarks
|
|
|
|
* **Ref Before:** \`$REF_BEFORE\`
|
|
* **Ref After:** \`$REF_AFTER\`
|
|
|
|
## Compile E2E
|
|
|
|
<details>
|
|
<summary>Results</summary>
|
|
|
|
\`\`\`
|
|
$(cat benchmarks_resolc)
|
|
\`\`\`
|
|
|
|
</details>
|
|
|
|
## Parse Yul
|
|
|
|
<details>
|
|
<summary>Results</summary>
|
|
|
|
\`\`\`
|
|
$(cat benchmarks_yul_parse)
|
|
\`\`\`
|
|
|
|
</details>
|
|
|
|
## Lower Yul
|
|
|
|
<details>
|
|
<summary>Results</summary>
|
|
|
|
\`\`\`
|
|
$(cat benchmarks_yul_lower)
|
|
\`\`\`
|
|
|
|
</details>
|
|
EOF
|
|
|
|
- name: Post PR Comment with Benchmark Report
|
|
if: ${{ inputs.pr_number }}
|
|
uses: marocchino/sticky-pull-request-comment@v2
|
|
with:
|
|
header: benchmark
|
|
number: ${{ inputs.pr_number }}
|
|
path: BENCHMARK_REPORT.md
|
|
|
|
- name: Upload Benchmark Results
|
|
if: ${{ !inputs.pr_number }}
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: benchmark-report
|
|
path: BENCHMARK_REPORT.md
|
|
retention-days: 7
|