Aggregate deployment gas statistics in --gas-stats output#8038
Aggregate deployment gas statistics in --gas-stats output#8038
--gas-stats output#8038Conversation
🦋 Changeset detectedLatest commit: 870c01c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
Updates Hardhat’s --gas-stats reporting to aggregate deployment gas measurements per contract (instead of keeping only the latest deployment), aligning deployment reporting with the existing function-call statistics approach.
Changes:
- Store per-contract deployment gas measurements as a list and compute aggregated stats (min/avg/median/max/count).
- Update the gas stats report to display aggregated deployment stats and remove the deployment size column.
- Update tests and add a changeset documenting the behavior change.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| v-next/hardhat/src/internal/builtin-plugins/gas-analytics/gas-analytics-manager.ts | Aggregates deployment gas measurements and updates report output to show deployment stats (min/avg/median/max/#deployments). |
| v-next/hardhat/test/internal/builtin-plugins/gas-analytics/gas-analytics-manager.ts | Updates aggregation/stat/report tests to validate the new deployment stats behavior and formatting. |
| .changeset/evil-beers-pump.md | Documents the patch change: deployment gas stats are now aggregated instead of showing only last deployment cost/size. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| type: "row", | ||
| cells: [ | ||
| `${contractGasStats.deployment.gas}`, | ||
| `${contractGasStats.deployment.size}`, | ||
| "", | ||
| `${contractGasStats.deployment.min}`, | ||
| `${contractGasStats.deployment.avg}`, | ||
| `${contractGasStats.deployment.median}`, | ||
| `${contractGasStats.deployment.max}`, | ||
| `${contractGasStats.deployment.calls}`, |
There was a problem hiding this comment.
The deployment stats data row uses an empty string for the first cell, so the column labeled "Deployment" has no value in the only row. Consider putting a label (e.g. "Deployment") in the row’s first cell (or making the first column header blank) to avoid a confusing blank column in the rendered output.
There was a problem hiding this comment.
If we use "Deployment" as the first cell in the row, we could remove the subheaders and keep only the top headers. We could even sort the table to place the deployment row first. Still, the first column header ("Function Name") might be a bit misleading. Wdyt @alcuadrado?
There was a problem hiding this comment.
If we do this, we'd also need to update the last column header.
There was a problem hiding this comment.
Some examples:
Initial suggestion:
╔═══════════════════════════════════════════════════════════════════════════════════════╗
║ contracts/Calculator.sol:Calculator ║
╟───────────────────────────────────┬────────┬─────────┬────────┬────────┬──────────────╢
║ Function name │ Min │ Average │ Median │ Max │ #calls ║
╟───────────────────────────────────┼────────┼─────────┼────────┼────────┼──────────────╢
║ divide │ 44316 │ 44316 │ 44316 │ 44316 │ 1 ║
║ multiply(uint256,uint256) │ 44254 │ 44254 │ 44254 │ 44254 │ 2 ║
║ multiply(uint256,uint256,uint256) │ 44875 │ 44875 │ 44875 │ 44875 │ 1 ║
║ reset │ 21485 │ 21485 │ 21485 │ 21485 │ 1 ║
║ result │ 23510 │ 23510 │ 23510 │ 23510 │ 6 ║
║ subtract │ 44213 │ 44213 │ 44213 │ 44213 │ 1 ║
╟───────────────────────────────────┼────────┼─────────┼────────┼────────┼──────────────╢
║ │ Min │ Average │ Median │ Max │ #deployments ║
╟───────────────────────────────────┼────────┼─────────┼────────┼────────┼──────────────╢
║ Deployment │ 288115 │ 288115 │ 288115 │ 288115 │ 1 ║
╚═══════════════════════════════════╧════════╧═════════╧════════╧════════╧══════════════╝
Alternative 1:
╔═══════════════════════════════════════════════════════════════════════════════════════╗
║ contracts/Calculator.sol:Calculator ║
╟───────────────────────────────────┬────────┬─────────┬────────┬────────┬──────────────╢
║ │ Min │ Average │ Median │ Max │ Count ║
╟───────────────────────────────────┼────────┼─────────┼────────┼────────┼──────────────╢
║ Deployment │ 288115 │ 288115 │ 288115 │ 288115 │ 1 ║
║ divide │ 44316 │ 44316 │ 44316 │ 44316 │ 1 ║
║ multiply(uint256,uint256) │ 44254 │ 44254 │ 44254 │ 44254 │ 2 ║
║ multiply(uint256,uint256,uint256) │ 44875 │ 44875 │ 44875 │ 44875 │ 1 ║
║ reset │ 21485 │ 21485 │ 21485 │ 21485 │ 1 ║
║ result │ 23510 │ 23510 │ 23510 │ 23510 │ 6 ║
║ subtract │ 44213 │ 44213 │ 44213 │ 44213 │ 1 ║
╚═══════════════════════════════════╧════════╧═════════╧════════╧════════╧══════════════╝
Deployment could be colorized to distinguish it from functions.
Alternative 2:
╔═══════════════════════════════════════════════════════════════════════════════════════╗
║ contracts/Calculator.sol:Calculator ║
╟───────────────────────────────────┬────────┬─────────┬────────┬────────┬──────────────╢
║ Function name │ Min │ Average │ Median │ Max │ #calls ║
╟───────────────────────────────────┼────────┼─────────┼────────┼────────┼──────────────╢
║ divide │ 44316 │ 44316 │ 44316 │ 44316 │ 1 ║
║ multiply(uint256,uint256) │ 44254 │ 44254 │ 44254 │ 44254 │ 2 ║
║ multiply(uint256,uint256,uint256) │ 44875 │ 44875 │ 44875 │ 44875 │ 1 ║
║ reset │ 21485 │ 21485 │ 21485 │ 21485 │ 1 ║
║ result │ 23510 │ 23510 │ 23510 │ 23510 │ 6 ║
║ subtract │ 44213 │ 44213 │ 44213 │ 44213 │ 1 ║
╟───────────────────────────────────┼────────┼─────────┼────────┼────────┼──────────────╢
║ Deployment │ 288115 │ 288115 │ 288115 │ 288115 │ 1 ║
╚═══════════════════════════════════╧════════╧═════════╧════════╧════════╧══════════════╝
--gas-stats output
eec7cb6 to
e62d33c
Compare
8ab302f to
126259a
Compare
|
Added an issue to edr to get the runtime size from the deployments, so we can show it in the --gas-stats table. |
|
Added #8059 |
343f139 to
3a35c9e
Compare
3a35c9e to
870c01c
Compare
Closes #8037.
Docs: NomicFoundation/hardhat-website#232
Output example: