blockful-io / swaplace-contracts

Swaplace is an open-source, ownerless and feeless token swap protocol
https://app.swaplace.xyz/
MIT License
33 stars 33 forks source link

refactor: gas optimization in Swaplace.sol #106

Closed blackbeard002 closed 11 months ago

blackbeard002 commented 11 months ago

Hey @0xneves,
In the function createSwap() the state variable 'swapId' is used thrice (excluding swapId++) making it 3 sloads. Instead storing 'swapId' to a local variable brings it down to 1 sload and using the local variable thrice reduces the gas cost.

And also incrementing the swapId in assembly saves gas.

0xneves commented 11 months ago

This is an amazing entry @blackbeard002 !!

I'm moving to review so I can further check on the gas optimization and legibility

0xneves commented 11 months ago

Closed by #107