Closed 0xjoaovpsantos closed 8 months ago
Let's go @0xjoaovpsantos 🔥
Hitting some scores:
1 - Using assembly to optimize will turn legibility in the opposite direction we expect.
2 - Allowed
should be indexed instead of expiry
as it is more important for tracking enrolled users in the swap.
2.1 - Event emission parameters should follow the same order as the Swap struct.
3 - The comparison table was lacking from the response so I had to test before and after changes.
3.1 - Adding allowed
in the createSwap event will add up to ~147 gas.
4 - Logging the bidding
and asking
assets will slightly increase gas consumption.
4.1 - Logging structs in assembly is a pain in the ass, I went after the resolution, and it is just not worth it.
I applied this PR resolution in my fork while comparing the gas differences. Please feel free to take a look, and commit in your branch, and we can move forward with this PR conclusion.
Nice job 😄
Thanky you @0xneves !!!!
I updated this PR with your recommendation in your branch refactor-logs: https://github.com/0xneves/swaplace-contracts/tree/refactor-logs
Sorry I forgot the compariosion table in the readme of PR :/, I'll improve in the next issues :)
docs: research gas and cost efficiency for event emission
closes #121
How I calculated the gas usage?
Prepare a spreadsheet with the gas usage based on the current and proposed events emitted and set for a comparison.
Estimate the gas when calling createSwap and record their gas usage.
Take measures of the gas usage.
Add the allowed field in the events. Take Measure.
Add the bidding and asking field in the events. Take Measure.
Add the price of ETH at $2.200 and calculate the gas cost in dollars.
Conclusion
After the study about gas usage in the swaplace, I came to the conclusion that we can add the "allowed" field in the "SwapCreated" event, but if we add the "biding" and "asking" fields, we will increase a lot the gas usage in the emit of events, so I this PR I added the "allowed" field in the swap created event and refactored all events to use assembly to reduce the gas usage.
And about the "biding" and "asking" fields, I think that is have a lot of gas usage and I'm studying about how we can emit the event with assembly there paramters, I tried but I couldn't, I'm trying yet :)
If possible, I need your review about this PR :), I'm ready to fix/improve something and work togheter!!!