Gas optimizations: loop and storage improvements#7
Open
eil-docbot wants to merge 8 commits intoeth-infinitism:masterfrom
Open
Gas optimizations: loop and storage improvements#7eil-docbot wants to merge 8 commits intoeth-infinitism:masterfrom
eil-docbot wants to merge 8 commits intoeth-infinitism:masterfrom
Conversation
* Add README.md --------- Co-authored-by: shahafn <shahaflol@gmail.com>
Fix typo in README
Applied loop optimizations to several core smart contracts:
- Cached array lengths outside loops.
- Used `unchecked { ++i }` for loop increments.
- Removed `= 0` initializations where appropriate.
Optimized files include:
- `src/CrossChainPaymaster.sol`
- `src/destination/DestinationSwapManager.sol`
- `src/destination/TokenDepositManager.sol`
- `src/origin/OriginSwapManager.sol`
Completed the remaining loop optimizations across various smart contracts, improving gas efficiency by caching array lengths and using unchecked increments. Optimized files: - `src/L2XlpRegistry.sol` - `src/destination/DestinationSwapDisputeManager.sol` - `src/L1AtomicSwapStakeManager.sol` - `src/origin/OriginationSwapDisputeManager.sol` - `src/bridges/arbitrum/L1ArbitrumBridgeConnector.sol` - `src/common/utils/XlpSelectionHelper.sol` - `src/bridges/optimism/L1OptimismBridgeConnector.sol` - `src/bridges/ethereum/L1EthereumLocalBridge.sol`
Reordered fields in several structs to optimize storage packing and reduce SLOADs. While the goal was to reduce gas costs, some functions saw slight increases, which might be due to complex access patterns for packed variables or compiler optimizations. Optimized files: - `eil-contracts/src/types/AtomicSwapMetadata.sol` - `eil-contracts/src/types/AtomicSwapVoucher.sol` - `eil-contracts/src/types/StakeManagerStructs.sol` Gas Benchmarks (after optimization): lockUserDeposit_singleAsset: 131330 (Previous: 131315, Diff: +15) lockUserDeposit_twoAssets: 134607 (Previous: 134592, Diff: +15) issueVouchers_single: 172636 (Previous: 171977, Diff: +659) issueVouchers_batch3: 403598 (Previous: 402653, Diff: +945) withdrawFromUserDeposit_single: 60007 (Previous: 59995, Diff: +12) cancelVoucherRequest: 77286 (Previous: 77296, Diff: -10) withdrawFromVoucher_single: 107420 (Previous: 107222, Diff: +198) depositToXlp_native: 44687 (Previous: 44711, Diff: -24) tokenDepositToXlp: 48395 (Previous: 48463, Diff: -68) multiTokenDepositToXlp_2: 111178 (Previous: 111246, Diff: -68) nativeWithdrawToXlp: 62096 (Previous: 62118, Diff: -22) tokenWithdraw: 60829 (Previous: 60917, Diff: -88)
Cached the `chainIds` array in memory before the loop in the `getChainInfos` function. This avoids repeated `SLOAD` operations for the `chainIds` array within the loop, leading to a reduction in gas costs for this function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getChainInfosin L1AtomicSwapStakeManagerAffects 15 files across the codebase including CrossChainPaymaster, L1AtomicSwapStakeManager, bridge connectors, and swap managers.