Skip to content

Conversation

@lababidi
Copy link

@lababidi lababidi commented Dec 19, 2025

Motivation

In the Gas Report, the gas values in the cells are left aligned which obfuscate and make difficult the ability to see where the highest gas functions are. See the table:

╭-----------------------------------------------+-----------------+-------+--------+-------+---------╮
| contracts/ShakyToken.sol:StableToken Contract |                 |       |        |       |         |
+====================================================================================================+
| Deployment Cost                               | Deployment Size |       |        |       |         |
|-----------------------------------------------+-----------------+-------+--------+-------+---------|
| 656818                                        | 3220            |       |        |       |         |
|-----------------------------------------------+-----------------+-------+--------+-------+---------|
|                                               |                 |       |        |       |         |
|-----------------------------------------------+-----------------+-------+--------+-------+---------|
| Function Name                                 | Min             | Avg   | Median | Max   | # Calls |
|-----------------------------------------------+-----------------+-------+--------+-------+---------|
| approve                                       | 26309           | 42386 | 46209  | 46257 | 233     |
|-----------------------------------------------+-----------------+-------+--------+-------+---------|
| balanceOf                                     | 2559            | 2559  | 2559   | 2559  | 4       |
╰-----------------------------------------------+-----------------+-------+--------+-------+---------╯

Solution

This PR solves that by aligned those specific gas cells with numeric values to be right-aligned which allow numbers to be properly aligned (similar to a spreadsheet).

Solves #12884

After the change they will be:

╭-----------------------------------------------+-----------------+-------+--------+-------+---------╮
| contracts/ShakyToken.sol:StableToken Contract |                 |       |        |       |         |
+====================================================================================================+
| Deployment Cost                               | Deployment Size |       |        |       |         |
|-----------------------------------------------+-----------------+-------+--------+-------+---------|
|                                         656818|             3220|       |        |       |         |
|-----------------------------------------------+-----------------+-------+--------+-------+---------|
|                                               |                 |       |        |       |         |
|-----------------------------------------------+-----------------+-------+--------+-------+---------|
| Function Name                                 | Min             | Avg   | Median | Max   | # Calls |
|-----------------------------------------------+-----------------+-------+--------+-------+---------|
| approve                                       |            26309|  42386|   46209|  46257|      233|
|-----------------------------------------------+-----------------+-------+--------+-------+---------|
| balanceOf                                     |             2559|   2559|    2559|   2559|        4|
╰-----------------------------------------------+-----------------+-------+--------+-------+---------╯

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@zerosnacks
Copy link
Member

I prefer the layout we currently have for visual clarity in the terminal, thanks for your suggestion

If you require a table you can easily copy you are pass the --markdown flag as follows:

forge test --gas-report --markdown

@zerosnacks zerosnacks closed this Dec 22, 2025
@github-project-automation github-project-automation bot moved this to Done in Foundry Dec 22, 2025
@lababidi
Copy link
Author

@zerosnacks Please explain to me how you compare two values that have different magnitudes 100 vs 1000

The way you currently have it the numbers stack up on top of each other without the magnitudes lining up. I don't want markdown. I want to look at it in the terminal and find the largest gas.

I would love to understand how you find you use the gas report with left aligned numbers.

@lababidi
Copy link
Author

@gakonst @DaniPopes @mattsse flagging you on this as additional eyes. would love more perspective.
Please look at the examples above and explain to me how misaligned numbers are easier to read?

@zerosnacks
Copy link
Member

I guess I do a sweep from end to front but apparently it is much more common to have numbers right aligned and scan the front and then infer the length.

Let's see if anyone else has a strong preference, nobody has complained about this before. I'll reopen.

@zerosnacks zerosnacks reopened this Dec 22, 2025
@zerosnacks zerosnacks changed the title Adjust Cells to be Right Aligned in Gas Report chore: adjust cells in gas report to be right aligned Dec 22, 2025
@zerosnacks zerosnacks changed the title chore: adjust cells in gas report to be right aligned fix: adjust cells in gas report to be right aligned Dec 22, 2025
@zerosnacks zerosnacks changed the title fix: adjust cells in gas report to be right aligned fix: adjust numerical cells in gas report to be right aligned Dec 22, 2025
@lababidi
Copy link
Author

@zerosnacks thanks for reopening!

I wonder if being right-aligned would help on the end-to-front scanning as well?

the other scenario is if two number have the same digits, you can quickly discern from the first digit which is larger (1000 vs 9000).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants