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

Potential Minor Gas Savings #561

Open
AlphaSerpentis opened this issue Jul 5, 2022 · 0 comments
Open

Potential Minor Gas Savings #561

AlphaSerpentis opened this issue Jul 5, 2022 · 0 comments

Comments

@AlphaSerpentis
Copy link

Throughout the code, there are potential areas to improve gas usage. These changes are minor and may not always be a massive change.

These changes aim for Crab v2, but can be applied elsewhere.

Types of Gas Optimizations

Usage of != 0 is gas-efficient over > 0 when used on a uint256 in a require statement

Source

Saves 6 gas/call

Present In:

Cache the Array's Length

Depending on whether the array is from storage, memory, or calldata, it can shave off gas usage per loop.

Present In:

  • contracts/strategy/CrabStrategyV2.sol

Unnecessary Zero-Initialization

In Solidity, values when not defined will have a zero-equivalent and thus, setting = 0 or other zero-equivalent is unnecessary and costs gas.

Present In:

  • contracts/strategy/CrabStrategyV2.sol
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

No branches or pull requests

1 participant