Cache addresses from resolver inside contracts to reduce gas usage.
Ensure that each contract relying on addresses from the
AddressResolver caches its own copy of these addresses, thereby reducing the gas usage for users when executing regular transactions like
exchange. The cache however must be refreshed on each and every deployment.
In our Achernar release (v2.19.8), we introduced SIP-43 - an address lookup contract into the
Issuer and all
Synth contracts, among others. The impact to gas on common user functions like
Synthetix.issueSynths was signficant.
Prior to Achernar
The biggest impact is to
exchange() however that was primarily due to SIP-37 (Fee Reclamation) that was also released in Achernar.
By caching the various required addresses, we can reduce these down and not worry about having to write code in each function to limit how often we lookup the addresses required.
- Introduce a local
mapping(bytes32 => address)cache into
MixinResolver- the functionality included in all contracts that need to communicate via the address resolver
MixinResolveris instantiated with a list of
bytes32addresses that the contract needs to know about
- Expose a function in
MixinResolver.setResolverAndSyncCache()to sync the cache. This is to be called each deployment whenever any new contracts are added.
Preliminary investigations after Caching and other improvements (such as SIP-41):
|Contract||Function||Gas Used||Diff from pre-Achenar||%|
- A local mapping in each
MixinResolverwill prevent unnecssary CALL opcodes from being used (approximately 1518 gas)
- Having the list of required address names in each
MixinResolverwill allow automated checks each deployment to know what needs updating in the AddressResolver
- After each deployment, determine which
MixinResolvercontracts need to be resynced based on the list in #2 above
Copyright and related rights waived via CC0.