Skip to content

feat: show contract runtime bytecode size in the gas stats table and JSON output#8108

Merged
schaable merged 1 commit intomainfrom
gas-stats-runtime-size
Apr 7, 2026
Merged

feat: show contract runtime bytecode size in the gas stats table and JSON output#8108
schaable merged 1 commit intomainfrom
gas-stats-runtime-size

Conversation

@schaable
Copy link
Copy Markdown
Member

@schaable schaable commented Apr 6, 2026

Capture the runtime size of the first deployment and display it as a new row at the bottom of the gas stats table and in the JSON output:

╔═══════════════════════════════════════════════════════════════════╗
║ contracts/Calculator.sol:Calculator                               ║
╟───────────────┬────────┬─────────┬────────┬────────┬──────────────╢
║ Function name │ Min    │ Average │ Median │ Max    │ #calls       ║
╟───────────────┼────────┼─────────┼────────┼────────┼──────────────╢
║ add           │ 14159  │ 28495   │ 14159  │ 69751  │ 209          ║
║ divide        │ 8618   │ 20033   │ 14218  │ 69774  │ 215          ║
║ lastOperation │ 2425   │ 2425    │ 2425   │ 2425   │ 3            ║
║ multiply      │ 8601   │ 27937   │ 14201  │ 69793  │ 141          ║
║ reset         │ 4612   │ 8099    │ 10212  │ 25021  │ 206          ║
║ result        │ 2469   │ 2469    │ 2469   │ 2469   │ 14           ║
║ subtract      │ 14186  │ 28970   │ 14186  │ 69754  │ 96           ║
╟───────────────┼────────┼─────────┼────────┼────────┼──────────────╢
║ Deployment    │ Min    │ Average │ Median │ Max    │ #deployments ║
╟───────────────┼────────┼─────────┼────────┼────────┼──────────────╢
║               │ 546337 │ 546337  │ 546337 │ 546337 │ 1            ║
╟───────────────┼────────┼─────────┴────────┴────────┴──────────────╢
║ Bytecode size │ 2294   │                                          ║
╚═══════════════╧════════╧══════════════════════════════════════════╝

Note: the original issue shows the "Bytecode size" row spanning the full table width (no trailing after 2294). This isn't currently possible with the existing hardhat-utils table helper without modifying it, and that change doesn't seem worth the added complexity for this case.

{
  "contracts": {
    "contracts/Calculator.sol:Calculator": {
      "sourceName": "contracts/Calculator.sol",
      "contractName": "Calculator",
      "deployment": {
        // ... other stats
        "runtimeSize": 2294
      },
      "functions": {
        // ...
      }
    }
    // ...
  }
}

Docs: NomicFoundation/hardhat-website#246

Closes #8059

Copilot AI review requested due to automatic review settings April 6, 2026 14:41
@schaable schaable self-assigned this Apr 6, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 6, 2026

🦋 Changeset detected

Latest commit: 5404ac8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
hardhat Patch

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds contract runtime bytecode size reporting to Hardhat’s gas analytics output, exposing it both in the console gas stats table and the --gas-stats-json output to address #8059.

Changes:

  • Plumbs runtimeSize from EDR gas reports into Hardhat gas measurements.
  • Extends gas stats aggregation + JSON schema to include deployment.runtimeSize.
  • Updates the gas stats table rendering and tests to display a “Bytecode size” row under deployment stats.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/hardhat/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.ts Maps EDR deployment runtimeSize into Hardhat deployment gas measurements.
packages/hardhat/src/internal/builtin-plugins/gas-analytics/types.ts Updates measurement/types and JSON output types to include runtimeSize.
packages/hardhat/src/internal/builtin-plugins/gas-analytics/gas-analytics-manager.ts Aggregates/stores deployment runtime size, renders it in the table, emits it in JSON.
packages/hardhat/test/internal/builtin-plugins/gas-analytics/gas-analytics-manager.ts Updates and extends tests for the new runtimeSize behavior and table output.
.changeset/cold-beers-knock.md Declares a patch release note for the new output fields/row.

Comment thread .changeset/cold-beers-knock.md
@schaable schaable added this pull request to the merge queue Apr 7, 2026
Merged via the queue into main with commit f08f6cb Apr 7, 2026
229 of 233 checks passed
@schaable schaable deleted the gas-stats-runtime-size branch April 7, 2026 13:01
@github-actions github-actions Bot mentioned this pull request Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add runtime bytecode size to --gas-stats table

3 participants