Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: sloads and increments in assembly for gas optimization. #179 #180

Merged
merged 2 commits into from
Jan 16, 2024

Conversation

blackbeard002
Copy link
Contributor

closes #179

@blackbeard002
Copy link
Contributor Author

Hey @0xneves ready for review

Copy link
Contributor

@0xneves 0xneves left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting the following changes:

unchecked {
assembly {
sstore(_totalSwaps.slot, add(sload(_totalSwaps.slot), 1))

swapId := sload(_totalSwaps.slot)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't change gas usage, we can use the previous way for better legibility

i++;
assembly {
i := mload(0x40)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove line 72

i := mload(0x40)

i := add(i, 1)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove line 74

i++;
assembly {
i := mload(0x40)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove line 91

i := mload(0x40)

i := add(i, 1)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove line 93

@@ -126,6 +140,14 @@ contract Swaplace is SwapFactory, ISwaplace, IERC165 {
* @dev Getter function for _totalSwaps.
*/
function totalSwaps() public view returns (uint256) {
return _totalSwaps;
uint256 swapId;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totalSwaps is never called on-chain, therefore there is no gas optm., we can keep the original way to preserve legibility

@blackbeard002
Copy link
Contributor Author

Hey @0xneves, done as requested. Ready for review.

@0xneves 0xneves merged commit 41d7563 into blockful-io:main Jan 16, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor: sloads and increments in assembly for gas optimization.
2 participants