Skip to content

Optimize condition in _disableInitializers#3787

Merged
frangio merged 1 commit intoOpenZeppelin:masterfrom
MathisGD:perf/disableInitializers
Nov 3, 2022
Merged

Optimize condition in _disableInitializers#3787
frangio merged 1 commit intoOpenZeppelin:masterfrom
MathisGD:perf/disableInitializers

Conversation

@MathisGD
Copy link
Copy Markdown
Contributor

@MathisGD MathisGD commented Oct 27, 2022

Minor optimization (2 gas) of _disableInitializers in Initializable.

A JUMP should happen if the condition is false. With != it requires only EQ (3 gas) while with < it requires LT + IZERO (3 + 2 gas).

PR Checklist

  • Tests
  • Documentation
  • Changelog entry

@MathisGD MathisGD force-pushed the perf/disableInitializers branch from 20f72ec to 6cc8653 Compare October 27, 2022 21:28
@Amxx Amxx requested a review from frangio October 31, 2022 09:47
@frangio frangio changed the title perf: save one ISZERO in _disableInitializers Optimize condition in _disableInitializers Nov 3, 2022
Copy link
Copy Markdown
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

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

Thanks @MathisGD. I'm really not happy that Solidity doesn't do this minor optimization on its own.

@frangio frangio merged commit 88a3f95 into OpenZeppelin:master Nov 3, 2022
@gitpoap-bot
Copy link
Copy Markdown

gitpoap-bot Bot commented Nov 3, 2022

Congrats, your important contribution to this open-source project has earned you a GitPOAP!

GitPOAP: 2022 OpenZeppelin Contracts Contributor:

GitPOAP: 2022 OpenZeppelin Contracts Contributor GitPOAP Badge

Head to gitpoap.io & connect your GitHub account to mint!

Learn more about GitPOAPs here.

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