You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Crypto Pizza example project has a isUnique function that traverses the whole array of Pizzas registered. This is a O(n) behaviour that could be simplified by creating a nameToPizzaId and dnaToPizzaId mapping to achieve O(1) complexity.
Motivation
Since this is an example project for people starting to use EthereumStudio, I don't think it'll be nice to encourage this sort of searches in a modifier function. Also, I was digging in the Solidity docs to see if modifiers somehow don't consume gas, but as far as explained in this answer, they do.
Describe alternatives you've considered
We can replace the isUnique modifier content with a O(1) check to nameToPizzaId and dnaToPizzaId mappings, in order to keep function working the same but with significantly less gas consumption.
I can implement it if there's no specific reason to keep it as it is.
Summary
Crypto Pizza example project has a
isUnique
function that traverses the whole array of Pizzas registered. This is a O(n) behaviour that could be simplified by creating anameToPizzaId
anddnaToPizzaId
mapping to achieve O(1) complexity.Motivation
Since this is an example project for people starting to use EthereumStudio, I don't think it'll be nice to encourage this sort of searches in a modifier function. Also, I was digging in the Solidity docs to see if modifiers somehow don't consume gas, but as far as explained in this answer, they do.
Describe alternatives you've considered
We can replace the isUnique modifier content with a O(1) check to
nameToPizzaId
anddnaToPizzaId
mappings, in order to keep function working the same but with significantly less gas consumption.I can implement it if there's no specific reason to keep it as it is.
Additional context
The isUnique function can be seen here
And here's the solidity documentation about modifiers. This is where I couldn't find any reason why it could be accepted to have an O(n) behaviour
The text was updated successfully, but these errors were encountered: