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

fix(forge): forge build --sizes collapses non uniques #9962

Merged

Conversation

zerosnacks
Copy link
Member

@zerosnacks zerosnacks commented Feb 26, 2025

Motivation

Closes: #9961

Previously, because of a flat BTreeMap, we were not preserving path-unique contracts in the --sizes table

Solution

Now includes the path, stripped by project root as the unique identifier only in cases where clashing occurs

╭-----------------------------+------------------+-------------------+--------------------+---------------------╮
| Contract                    | Runtime Size (B) | Initcode Size (B) | Runtime Margin (B) | Initcode Margin (B) |
+===============================================================================================================+
| Counter (src/Counter.sol)   | 481              | 509               | 24,095             | 48,643              |
|-----------------------------+------------------+-------------------+--------------------+---------------------|
| Counter (src/a/Counter.sol) | 344              | 372               | 24,232             | 48,780              |
|-----------------------------+------------------+-------------------+--------------------+---------------------|
| Counter (src/b/Counter.sol) | 291              | 319               | 24,285             | 48,833              |
|-----------------------------+------------------+-------------------+--------------------+---------------------|
| Foo                         | 62               | 88                | 24,514             | 49,064              |
╰-----------------------------+------------------+-------------------+--------------------+---------------------╯

and with --json:

{
   "Counter (src/Counter.sol)":{
      "runtime_size":481,
      "init_size":509,
      "runtime_margin":24095,
      "init_margin":48643
   },
   "Counter (src/a/Counter.sol)":{
      "runtime_size":344,
      "init_size":372,
      "runtime_margin":24232,
      "init_margin":48780
   },
   "Counter (src/b/Counter.sol)":{
      "runtime_size":291,
      "init_size":319,
      "runtime_margin":24285,
      "init_margin":48833
   },
   "Foo":{
      "runtime_size":62,
      "init_size":88,
      "runtime_margin":24514,
      "init_margin":49064
   }
}

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@zerosnacks zerosnacks added C-forge Command: forge T-bug Type: bug labels Feb 26, 2025
@zerosnacks zerosnacks changed the title fix: forge build sizes collapses non unique fix(forge): forge build --sizes collapses non unique Feb 26, 2025
@zerosnacks zerosnacks changed the title fix(forge): forge build --sizes collapses non unique fix(forge): forge build --sizes collapses non uniques Feb 26, 2025
Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

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

Makes sense. Not sure if we should display path to artifact or actually path to source file, wdyt?

@zerosnacks
Copy link
Member Author

Makes sense. Not sure if we should display path to artifact or actually path to source file, wdyt?

Ah yes, that makes much more sense - fixed in 7e9020c

@zerosnacks zerosnacks requested a review from grandizzy February 26, 2025 14:32
Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

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

lgtm! Don't think there's any implications on json output?

@zerosnacks
Copy link
Member Author

zerosnacks commented Feb 26, 2025

lgtm! Don't think there's any implications on json output?

it does not, added test for completeness

the only implication is that in the JSON output it would also show with the path in the name

{
   "Counter (src/Counter.sol)":{
      "runtime_size":481,
      "init_size":509,
      "runtime_margin":24095,
      "init_margin":48643
   },
   "Counter (src/a/Counter.sol)":{
      "runtime_size":344,
      "init_size":372,
      "runtime_margin":24232,
      "init_margin":48780
   },
   "Counter (src/b/Counter.sol)":{
      "runtime_size":291,
      "init_size":319,
      "runtime_margin":24285,
      "init_margin":48833
   },
   "Foo":{
      "runtime_size":62,
      "init_size":88,
      "runtime_margin":24514,
      "init_margin":49064
   }
}

I would classify it as a fix rather than a breaking change, previously it would show just one "Counter": { ... } which is incorrect

@zerosnacks zerosnacks merged commit 4830840 into master Feb 26, 2025
22 checks passed
@zerosnacks zerosnacks deleted the zerosnacks/fix-forge-build-sizes-collapses-non-unique branch February 26, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge T-bug Type: bug
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

bug(forge): forge build --sizes does not show all contracts with duplicated names
2 participants