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.
Hi ! Two weeks ago I made a PR improving the
pascal
function, because it was a bottleneck. I continued investigating and I found that it was often called with the same values. So this PR adds a very simple cache to this function, with a tremendous impact on performance.Obvious duplicated calls to the pascal function
Hidden duplicated calls
Some calls are made from different places of the codebase with the same input.
Solution proposed
A simple object acting as a cache.
Screenshots of the result
Before

After

99.9%+ hit ratio, this is huge !
Also, we can see that the memory does not grow too much, even with 15 million calls to the
pascal
function, it have only 10k keys, so it does not damage the user's memory. ✅ No need for a real cache library.Going further
The default
petstore.yml
really is not a good OpenAPI doc to test on, because we can see that it does not have the size of a real project. Maybe a good idea for the future might be to test on a bigger document ?