zarr-python icon indicating copy to clipboard operation
zarr-python copied to clipboard

Improve LRU Store Cache Performance by Partial Key Cache Update

Open Yannicked opened this issue 2 years ago • 2 comments

When data is added/updated in an LRU store, the keys_cache and contains_cache are invalidated. In my case this causes a large slowdown due to occasional writes and many reads because my underlying store has a slow keys() function.

To address this problem, I propose introducing a _update_key function that will be called from the __setitem__ function. This new function will specifically add the key to the key/contains cache, without wiping the entire cache. By doing so, we can avoid unnecessary cache invalidations and reduce the slowdown associated with occasional writes.

Furthermore, I believe a similar enhancement can be made to the __delitem__ function. This would allow us to remove a key from the key/contains cache, without invalidating it.

TODO:

  • [ ] Add unit tests and/or doctests in docstrings
  • [ ] Add docstrings and API docs for any new/modified user-facing classes and functions
  • [ ] New/modified features documented in docs/tutorial.rst
  • [ ] Changes documented in docs/release.rst
  • [ ] GitHub Actions have all passed
  • [ ] Test coverage is 100% (Codecov passes)

Yannicked avatar Jul 31 '23 15:07 Yannicked

Workflows launched if anyone wants to jump in for review.

joshmoore avatar Aug 02 '23 09:08 joshmoore

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (6ed4d78) to head (37ad518). Report is 588 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1481   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           37        37           
  Lines        14732     14738    +6     
=========================================
+ Hits         14732     14738    +6     
Files with missing lines Coverage Δ
zarr/storage.py 100.00% <100.00%> (ø)
zarr/tests/test_storage.py 100.00% <100.00%> (ø)

codecov[bot] avatar Aug 02 '23 09:08 codecov[bot]

I'm going to close this as stale. Folks should feel free to reopen if there is interest in continuing this work.

jhamman avatar Oct 11 '24 23:10 jhamman