Conversation
src/lens/TickDataLens.sol
Outdated
| mstore(add(offset, 0x20), currencyDemandQ96) | ||
| mstore(add(offset, 0x40), requiredCurrencyDemandQ96) | ||
| mstore(add(offset, 0x60), currencyRequiredQ96) | ||
| mstore(0x40, add(offset, 0x80)) |
There was a problem hiding this comment.
Can be done once at the end, does not have to happen in every iteration. As far as I can see, there is no memory allocated other then this inside the while loop, only stack variables, so should be safe.
src/lens/TickDataLens.sol
Outdated
| mstore(buffer, idx) | ||
| let headerSize := add(0x20, shl(5, idx)) // 32 + idx * 32 | ||
| let dataSize := shl(7, idx) // idx * 128 | ||
| mcopy(add(fmp, headerSize), fmp, dataSize) |
There was a problem hiding this comment.
This mcopy is very expensive in this case, since it must copy all of the previously created data in memory to a different location. I understand where you are coming from with this, but you can handle this easier:
The memory setup for an array of a static struct is, as you have correctly documented:
[length][absolute pointer1][absolute pointer2][absolute pointer3][struct content1][struct content2][struct content3]
Reminder, these pointers are absolute values! You can simply continue at the updated free memory pointer with the array length and then point to the previously created structs in memory.
Would something like this:
[struct content1][struct content2][struct content3][length][absolute pointer1][absolute pointer2][absolute pointer3]
Afaik, this should work as well and skips this expensive operation
refactor: optimize TickDataLens memory handling
No description provided.