clones-with-immutable-args icon indicating copy to clipboard operation
clones-with-immutable-args copied to clipboard

Memory copy loop optimization

Open k06a opened this issue 3 years ago • 6 comments

This loop could be replaced with CALLDATACOPY():

https://github.com/wighawag/clones-with-immutable-args/blob/5950723ffcfa047f13262e5dbd7218b54360c42e/src/ClonesWithImmutableArgs.sol#L126-L134

k06a avatar Jan 25 '22 01:01 k06a

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).

hrkrshnn avatar Jan 26 '22 12:01 hrkrshnn

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

k06a avatar Jan 26 '22 12:01 k06a

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

BlinkyStitt avatar Mar 01 '22 19:03 BlinkyStitt

this looks great. any thoughts on integrating @wighawag ?

z0r0z avatar Apr 10 '22 10:04 z0r0z

Implemented this optimization using the identity precompile on this fork in case anyone's interested: https://github.com/RollaProject/clones-with-immutable-args/commit/3cef7aeca219cdfb3370c3e7a59f40c022fc89ae

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

0xca11 avatar May 23 '22 11:05 0xca11

How much did deploy and call costs change with the identity precompile?

On May 23, 2022, at 4:16 AM, 0xca11.eth @.***> wrote:

 Implemented this optimization using the identity precompile on this fork in case anyone's interested: @.***

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

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

BlinkyStitt avatar May 23 '22 14:05 BlinkyStitt