Skip to content

Gas benchmark for DiamondLoupeContract#165

Merged
mudgen merged 7 commits intoPerfect-Abstractions:mainfrom
lumoswiz:bench/diamond-gas-200facets
Nov 2, 2025
Merged

Gas benchmark for DiamondLoupeContract#165
mudgen merged 7 commits intoPerfect-Abstractions:mainfrom
lumoswiz:bench/diamond-gas-200facets

Conversation

@lumoswiz
Copy link
Copy Markdown
Collaborator

@lumoswiz lumoswiz commented Nov 2, 2025

Summary

To aid evaluation of #155.

Adds a reusable gas benchmark harness for Diamond Loupe. It spins up a minimal diamond, plugs in a user-provided loupe facet, and synthetically builds a large diamond in storage (default: 200 facets × 10 selectors) so anyone can drop in an optimised loupe and immediately measure gas for the four view functions.

Changes Made

To tests/benchmark, added:

  • MinimalDiamond.sol: adapted from a reference implementation.
  • Base.t.sol: abstract test harness that deploys MinimalDiamond setup with four loupe selectors, and builds complex storage for the diamond.
  • Utils.sol: storage helpers, constants and builder functions.
  • Benchmark.t.sol: baseline gas tests against current DiamondLoupeFacet.
  • Optimised.t.sol: same tests as the benchmark, but _deployLoupe should be overriden with the optimised contract.

Checklist

Before submitting this PR, please ensure:

  • Code follows the Solidity feature ban - No inheritance, constructors, modifiers, public/private variables, external library functions, using for directives, or selfdestruct

  • Code follows Design Principles - Readable, uses diamond storage, favors composition over inheritance

  • Code matches the codebase style - Consistent formatting, documentation, and patterns (e.g. ERC20Facet.sol)

  • Code is formatted with forge fmt

  • Tests are included - All new functionality has comprehensive tests

  • All tests pass - Run forge test and ensure everything works

  • Documentation updated - If applicable, update relevant documentation

Make sure to follow the CONTRIBUTING.md guidelines.

Additional Notes

Run benchmarks with:
forge test --mt LoupeGasBenchmarkTest -vv
forge test --mt OptimisedLoupeBenchmarkTest -vv

@lumoswiz lumoswiz mentioned this pull request Nov 2, 2025
@lumoswiz lumoswiz changed the title Bench/diamond gas 200 facets Gas benchmark for DiamondLoupeContract Nov 2, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 2, 2025

Coverage Report

Coverage

Metric Coverage Details
Lines 49% 667/1370 lines
Functions 62% 143/232 functions
Branches 25% 63/249 branches

Last updated: Sun, 02 Nov 2025 22:06:38 GMT for commit 1161789

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 2, 2025

Gas Report

No gas usage changes detected between main and bench/diamond-gas-200facets.

All functions maintain the same gas costs. ✅

Last updated: Sun, 02 Nov 2025 22:06:53 GMT for commit 1161789

@mudgen
Copy link
Copy Markdown
Contributor

mudgen commented Nov 2, 2025

Thanks, I am going to try this out! The formatting check forge -fmt --check failed, but I will fix that.

@mudgen mudgen merged commit 2329c91 into Perfect-Abstractions:main Nov 2, 2025
3 of 4 checks passed
@mudgen
Copy link
Copy Markdown
Contributor

mudgen commented Nov 2, 2025

I tried it out, it works!

JackieXu pushed a commit to JackieXu/Compose that referenced this pull request Nov 6, 2025
…nd-gas-200facets

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants