You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Caching the length saves gas. Moreover not assigning the default value 0 to i save gas;
Reference implementation
uint256 len = array.length;
for (uint256; i < len; ++i) {
// Operations
}
Scope:
./core/LensHub.sol:541: for (uint256 i = 0; i < vars.datas.length; ++i) {
./core/modules/follow/ApprovalFollowModule.sol:41: for (uint256 i = 0; i < addresses.length; ++i) {
./core/modules/follow/ApprovalFollowModule.sol:66: for (uint256 i = 0; i < addresses.length; ++i) {
./core/modules/follow/ApprovalFollowModule.sol:128: for (uint256 i = 0; i < toCheck.length; ++i) {
./libraries/InteractionLogic.sol:47: for (uint256 i = 0; i < profileIds.length; ++i) {
./libraries/PublishingLogic.sol:403: for (uint256 i = 0; i < byteHandle.length; ++i) {
Use bit-shift to save gas rather than dividing by 2
Scope:
./core/FollowNFT.sol:134: uint256 center = upper - (upper - lower) / 2;
./core/FollowNFT.sol:176: uint256 center = upper - (upper - lower) / 2;
./core/LensHub.sol:27: * 2. Almost every event in the protocol emits the current block timestamp, reducing the need to fetch it manually.
./core/base/ERC721Time.sol:20: * 2. Constructor replaced with an initializer.
./core/modules/ModuleGlobals.sol:109: if (newTreasuryFee >= BPS_MAX / 2) revert Errors.InitParamsInvalid();
Use increment, when possible
In the code base += 1 is used, but using preincrement ++ is cheaper. (Same applies for substraction)
Caching is included in lens-protocol/core#80, the rest, although valid except for the zero initialization (which is handled by the optimizer now afaik), we won't be taking any action on.
Implement loops more efficiently
Caching the length saves gas. Moreover not assigning the default value 0 to i save gas;
Reference implementation
Scope:
For
uint
use!= 0
rather than> 0
It costs less gas to do so.
Scope:
Do not assign default values to save gas
Scope:
uint256 x;
costs less gas thenuint256 x = 0;
.Use bit-shift to save gas rather than dividing by 2
Scope:
Use increment, when possible
In the code base
+= 1
is used, but using preincrement++
is cheaper. (Same applies for substraction)Scope:
The text was updated successfully, but these errors were encountered: