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

Memory copy loop optimization #2

Open
k06a opened this issue Jan 25, 2022 · 6 comments
Open

Memory copy loop optimization #2

k06a opened this issue Jan 25, 2022 · 6 comments

Comments

@k06a
Copy link
Contributor

k06a commented Jan 25, 2022

This loop could be replaced with CALLDATACOPY():

for (; counter >= 32; counter -= 32) {
// solhint-disable-next-line no-inline-assembly
assembly {
mstore(copyPtr, mload(dataPtr))
}
copyPtr += 32;
dataPtr += 32;
}

@hrkrshnn
Copy link
Contributor

Alternatively, if one really wants to keep the data in memory, one can use the identity precompile to copy from memory to memory. It should be cheaper if that loop runs more than 2 times (please check).

@k06a
Copy link
Contributor Author

k06a commented Jan 26, 2022

Yep, I see method is internal and argument is not calldata, then really consider using “identity” precompile for copying

@BlinkyStitt
Copy link

BlinkyStitt commented Mar 1, 2022

If that loop is replaced, copyPtr and dataPtr both need to be increased still, right?

And I think counter needs to be decreased, too. Otherwise mask will be wrong

@z0r0z
Copy link
Contributor

z0r0z commented Apr 10, 2022

this looks great. any thoughts on integrating @wighawag ?

@0xca11
Copy link

0xca11 commented May 23, 2022

Implemented this optimization using the identity precompile on this fork in case anyone's interested: RollaProject@3cef7ae

@z0r0z @wighawag Please let me know if a PR with this change would be welcome :)

@BlinkyStitt
Copy link

BlinkyStitt commented May 23, 2022 via email

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

No branches or pull requests

5 participants