v4-core icon indicating copy to clipboard operation
v4-core copied to clipboard

Use packed stack-based version of Slot0 structure

Open 0xVolosnikov opened this issue 1 year ago • 1 comments
trafficstars

This pull request does not relate to any issue. In my opinion, it is more convenient to discuss this change if you have an already written implementation in a pull request.

Description of changes

The slot0 structure by design fits into one storage slot. However, when using the memory version of this structure, each field occupies a separate memory slot. In addition, the memory structure takes up more space on the solidity "stack".

The changes I propose allows to read this structure onto the stack and operate with the fields of this structure directly on the stack. As a result, the amount of memory used is reduced, which a little bit reduces gas costs and bytecode size.

Since the changes are more or less significant, I would first like to hear the opinion of the community and maintainers regarding the proposal to use a structure on the stack before adding tests and so on.

0xVolosnikov avatar Apr 25 '24 07:04 0xVolosnikov

Btw in general, I do really like this change and it would be great to get tests I think! cc @hensha256

snreynolds avatar May 14 '24 18:05 snreynolds

Added tests

0xVolosnikov avatar May 16 '24 21:05 0xVolosnikov

@snreynolds anything else you wanna see before we merge?

hensha256 avatar May 16 '24 21:05 hensha256