Small runtime optimizations (variable lookup speeds) #11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Depending on the dice roll configuration many thousand (or even millions) of dice input will be processed.
Due to a design decision there really isn't any algorithmic optimization that can be made (and also maintain the flexibility of the program).
With that in mind, any function that is going to be ran in the time intensive loop in the program will have optimizations in the area of variable look up speeds.
The key optimization was to make any global or builtin lookup be a local lookup. In some cases a lookup in the function closure was the best that can be done since the function signature of the actual function to be ran wouldn't of supported extra keywords.
This is inspired by the python documentation at the end of the
itertools
library at the end of the recipes sections.This idea is also talked about in a stackoverflow post which eludes to the fact that this is probably no longer as big as an issue as it used to be.
Another optimization implemented is to remove
lambda
functions in any part that would have been called in the time intensive loop. Though it seems the improvements are minor based of this. I also looked into this:Another runtime preformance article here.