Skip to content

Tweak optimizer config #1405

@fullkomnun

Description

@fullkomnun

The solc optimizer config can be tweaked using the following properties:

  • Solidity version (current: 0.8.17, latest: 0.8.19)
  • Optimizer enabled (current: true)
  • Yul IR pipeline enabled (current: false)
  • Runs (current: 1 for truffle, 200 for hardhat, range: 1 - 4_294_967_295)
  • Additional optimizer flags (reference, docs)
  • Marking an inline assmebly block with "memory-safe" where applicable
  • Config may be overidden per contract (reference)

These affect the following metrics:

  • Solc compilation time (time npx hardhat compile --force)
  • Contracts deployment size (npx hardhat size-contracts)
  • Contracts deployment gas costs (npm run test)
  • Transaction execution gas costs (npm run test + 'test-gas' CI job)

General rules of thumb:

  • Lower optimizer runs = favors contract sizes and deployment cost over tx exceution costs (and vice versa)
  • Yul ir pipeline increases the compilation time significantly
  • Yul ir pipeline reduces contract sizes and deployment gas costs
  • Yul ir pipeline mostly seem to slightly increase tx execution gas costs
  • Recent hardhat V2.13.0 release has added better support for yul ir pipeline

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions