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

put market in memory instead of calldata #152

Merged
merged 8 commits into from
Jul 25, 2023
Merged

put market in memory instead of calldata #152

merged 8 commits into from
Jul 25, 2023

Conversation

MerlinEgalite
Copy link
Contributor

Fixes #144

Few questions:

  • Should we move these new functions to an helper library instead?
  • Should we rename id to idCalldata or something similar?

@MerlinEgalite MerlinEgalite marked this pull request as ready for review July 20, 2023 15:50
@Rubilmax
Copy link
Collaborator

@MathisGD suggested to actually move from calldata to memory: #144 (comment)

But for completeness, we'd have to expose a calldata-based getter anyway, right?

On a side note, this PR looks ridiculous but we'll actually use such function/library in the test suite - perhaps we could include some change to illustrate it.

@MerlinEgalite
Copy link
Contributor Author

@MathisGD suggested to actually move from calldata to memory: #144 (comment)

But calldata is actually cheaper so I don't think we should this tbh.

But for completeness, we'd have to expose a calldata-based getter anyway, right?

Yes.

On a side note, this PR looks ridiculous but we'll actually use such function/library in the test suite - perhaps we could include some change to illustrate it.

Yes I'll adapt

@makcandrov
Copy link
Contributor

So bad that Solidity doesn't allow giving the same name to all the functions...

Should we move these new functions to an helper library instead?

I find it more elegant to keep them in the same library. Also, we might need them in Blue at some point.

Should we rename id to idCalldata or something similar?

From the library's perspective, I find it more elegant to remain consistent and always specify the variable location. But it does burden Blue's code... Maybe we can shorten the names? Something like idc, idm, & ids?

But calldata is actually cheaper so I don't think we should this tbh.

I agree that we should keep calldata.

@MerlinEgalite
Copy link
Contributor Author

From the library's perspective, I find it more elegant to remain consistent and always specify the variable location. But it does burden Blue's code... Maybe we can shorten the names? Something like idc, idm, & ids?

Can be better yers but I think ids is very misleading though

@Rubilmax
Copy link
Collaborator

mId, sId, cId? memId, stgId, cdtId?

@makcandrov
Copy link
Contributor

mId, sId, cId? memId, stgId, cdtId?

I'm ok with mId, sId & cId.
stg & cdt seem weird

@MerlinEgalite
Copy link
Contributor Author

another option is to indeed use idCalldata, idMemory & idStorage but use an alias when importing a specific function. Not sure I prefer this way though.

@Rubilmax
Copy link
Collaborator

another option is to indeed use idCalldata, idMemory & idStorage but use an alias when importing a specific function. Not sure I prefer this way though.

This is neat! So we can minimize changes in Blue (if we really want to lol). But is there a syntax for it in Solidity, for internal library functions?

@MerlinEgalite
Copy link
Contributor Author

MerlinEgalite commented Jul 21, 2023

another option is to indeed use idCalldata, idMemory & idStorage but use an alias when importing a specific function. Not sure I prefer this way though.

This is neat! So we can minimize changes in Blue (if we really want to lol). But is there a syntax for it in Solidity, for internal library functions?

I'll try it!

EDIT: seems impossible indeed...

@MathisGD
Copy link
Contributor

MathisGD commented Jul 23, 2023

But calldata is actually cheaper so I don't think we should this tbh.

Did you try it ? I'm not so sure

If it's not, I'm in favor of using memory everywhere and don't apply this change which is very ugly.

@makcandrov
Copy link
Contributor

Did you try it ? I'm not so sure

In our case, indeed, specifying calldata doesn't bring any optimization because the first thing we do in every function is to hash the data (to get the id). Hashing requires having the data in memory, thus copying it into memory if it was not (which is exactly what specifying calldata avoids doing).

@MerlinEgalite
Copy link
Contributor Author

So should I go back to id and idStorage?

@Rubilmax
Copy link
Collaborator

Rubilmax commented Jul 24, 2023

So should I go back to id and idStorage?

I'm ok with id and sId as well as mId & sId as well as memId & stgId. But if you really want idStorage, I won't block the discussion because it's just that I find it ugly.

@MerlinEgalite
Copy link
Contributor Author

Actually using memory saves gas except for the liquidation:

Screenshot 2023-07-24 at 15 17 17

Rubilmax
Rubilmax previously approved these changes Jul 24, 2023
Rubilmax
Rubilmax previously approved these changes Jul 24, 2023
Jean-Grimal
Jean-Grimal previously approved these changes Jul 24, 2023
pakim249CAL
pakim249CAL previously approved these changes Jul 24, 2023
src/libraries/MarketLib.sol Outdated Show resolved Hide resolved
@MerlinEgalite MerlinEgalite dismissed stale reviews from pakim249CAL, Jean-Grimal, and Rubilmax via db1afdb July 24, 2023 18:13
@MathisGD MathisGD changed the title Add id lib function for memory or storage variables put market in memory instead of calldata Jul 24, 2023
@MathisGD MathisGD merged commit 5d00928 into main Jul 25, 2023
@MathisGD MathisGD deleted the feat/id-variants branch July 25, 2023 11:29
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.

Create an id lib function for memory or storage variables
6 participants