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

Consider refactoring code to save GAS #111

Closed
lknix opened this issue Jun 24, 2018 · 2 comments
Closed

Consider refactoring code to save GAS #111

lknix opened this issue Jun 24, 2018 · 2 comments
Assignees

Comments

@lknix
Copy link
Contributor

lknix commented Jun 24, 2018

@mg6maciej suggested: #109 (review)

If we do this, we should do it everywhere where this is applicable.

@MoMannn
Copy link
Collaborator

MoMannn commented Jun 25, 2018

I did a few tests around this to see what is the most gas optimal way to calculate. Here are the results:

Option tested Gas cost of mint function
push tokens then get index with: tokens.length.sub(1) 158760
push tokens then get index with: tokens.length - 1 158665
get lenght as a result from push then calculate index as -1 from that lenght 158465
get lenght as a result from push then calculate index as .sub(1) from that lenght 158560
first get lenght then push token then just set the lenght 158672

As you can see the suggested way is indeed the most GAS efficient. The subtraction is done after push so there is no need to use safemath library for the subtraction.

As such we will do this change everywhere where it is applicable. PR coming soon.

@MoMannn
Copy link
Collaborator

MoMannn commented Jun 25, 2018

#117

@MoMannn MoMannn closed this as completed Jun 25, 2018
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

No branches or pull requests

2 participants