-
Notifications
You must be signed in to change notification settings - Fork 4
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
Yul optimisation #2
Comments
Another function I converted:
|
The 721A version and notes can be found in my comment here: |
@sillytuna This is interesting. Do you have a gas usage comparison (with solidity optimizer enabled)? |
I was testing in situ. Marginal gains from the second two funcs but worth it on something like this, esp if could be called a lot. Should be quick for you to put in your code and run a quick gas comparison tho. |
My concern is it may affect the code readability. I also saw you lengthless array PR for ERC721A. Maybe shifting from mapping to lengthless array for the bitMap datastructure will be a bigger improvement. |
My view on that is it depends on use. Code like this can be needed in gas performant functions and will be write once use many. I'd keep the original solidity in hand to be read for sure and yul would need well testing and gas checks. Your code is already quite hard to understand just because of the algorithm so I'm not sure yul really changes that. Can be well commented and include solidity comments. |
I took a look and it seems the gas saving comes from two factors:
Unless there is a good reason, I don't think |
Makes sense. I forgot that I'd removed that require because of the specific use case essentially having it covered. It's certainly worth checking what's worth being yul / inline and what isn't. |
Solidity does a pretty good job generally but some things help, for example:
Whereas this function was the same either way:
However, I've done a test version with Chiru's 4.2 ERC721A (combined with a lengthless array optimisation around storage for this and another struct) and it was easiest to simply port across the two functions used and merge them in rather than me go through and yul/test the solidity-bits lib.
Happy to help if you want the lib improved though.
The text was updated successfully, but these errors were encountered: