rabbitholegg / quest-protocol

Quests Protocol is a protocol to distribute token rewards for completing on-chain tasks.
GNU General Public License v3.0
88 stars 22 forks source link

Public view vs external&internal view #186

Open Quazia opened 1 year ago

Quazia commented 1 year ago

There's a few places we use a public view where we could have an internal view that's accessible by way of another external view.

For example:

    function getNftQuestFee(address address_) public view returns (uint256) {
        return nftQuestFeeList[address_].exists ? nftQuestFeeList[address_].fee : nftQuestFee;
    }

Would become:

    function getNftQuestFee(address address_) external view returns (uint256) {
        _getNftQuestFee(address_);
    }

     function _getNftQuestFee(address address_) internal view returns (uint256) {
        return nftQuestFeeList[address_].exists ? nftQuestFeeList[address_].fee : nftQuestFee;
    }
waynehoover commented 1 year ago

Could you tell me what the reason is for this change?

Quazia commented 1 year ago

It's just a gas improvement, not super pressing. As far as I know internal and external are both more efficient than public. It's possible recent compiler optimizations have made this an outdated optimization and I think if you crank the solc optimization up enough it actually handles stuff like this. I can wait and do the gas testing before making this change so we can see sure. It takes up more storage in exchange for a little cheaper execution. You see a lot more benefit in situations where you're calling the same public function multiple times internally.