Skip to content
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

Optimize _remove_token_from_all_tokens_enumeration #326

Merged
merged 3 commits into from
Jun 14, 2022

Conversation

andrew-fleming
Copy link
Collaborator

@andrew-fleming andrew-fleming commented May 20, 2022

This PR proposes to optimize the ERC721 Enumerable library—specifically, the _remove_token_from_all_tokens_enumeration method. Below is a table comparison based on the current tests and here's a gist with the updated library, tests with print statements to replicate the numbers, and a modified tox.ini to print the results.

Burn first token Current New Saves
burn 2334 steps 2211 steps 5.26%

Burn last token Current New Saves
burn 2254 steps 1975 steps 12.37%

@andrew-fleming andrew-fleming changed the title Optimize erc721 enumeration Optimize _remove_token_from_all_tokens_enumeration May 23, 2022
Copy link
Contributor

@martriay martriay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good improvement


let (new_supply: Uint256) = SafeUint256.sub_le(supply, Uint256(1, 0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh benchmarking might be tricky: how do we know adding the if isn't less performant, but we don't notice due this line making up for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants