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

Adding LRU cache to make Range lookups much faster #124

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ludu12
Copy link

@ludu12 ludu12 commented Sep 15, 2024

Noticed that one of our models was performing poorly due to the compute going on in Range.js. This model is mostly made up of large vlookup tables and so everytime we had to lookup a value, we had to recreate the 2d matrix that made up the table. This was being done hundreds of times within the same "recalculation".

This PR adds a cache in front of this calculation so that these tables are created once.

I've added a script along with a dumbed down version of our model to show case the improvement:

Before:

xlsx-calc git:(main) ✗ node benchmarking/range.js
Average time for 100 executions: 155.09 ms

After:

xlsx-calc git:(main) ✗ node benchmarking/range.js
Average time for 100 executions: 3.92 ms

Comment on lines +787 to +788
cache = require('../src/Range.js').cache;
cache.clear();
Copy link
Author

Choose a reason for hiding this comment

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

Cache needs to be cleared for this test.

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.

1 participant