mudgen / diamond-1-hardhat

EIP-2535 Diamond reference implementation using Hardhat and Solidity 0.8.*
MIT License
135 stars 84 forks source link

Optimization fallback() function #1

Closed YingQm closed 2 years ago

YingQm commented 2 years ago

In Diamond.sol fallback function

 LibDiamond.DiamondStorage storage ds;
        bytes32 position = LibDiamond.DIAMOND_STORAGE_POSITION;
        // get diamond storage
        assembly {
            ds.slot := position
        }

why not use LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();?

mudgen commented 2 years ago

Because using LibDiamond.diamondStorage() costs a bit more gas and the fallback is very frequently called.