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

Possibility to improve deletion in lru cache using swap back method? #185

Open
Yomguithereal opened this issue Jun 9, 2022 · 2 comments

Comments

@Yomguithereal
Copy link
Owner

No description provided.

@mrflip
Copy link
Contributor

mrflip commented Aug 5, 2022

Could you say a bit more about this? I assume it would mean to preserve the carcasses of bookkeeping data structures in an lru-with-deletion once they have been made, to avoid repeated object creation/destruction?
How big is the performance hit and is it for all use cases?

@Yomguithereal
Copy link
Owner Author

Yomguithereal commented Aug 8, 2022

Hello @mrflip,

I assume it would mean to preserve the carcasses of bookkeeping data structures in an lru-with-deletion once they have been made, to avoid repeated object creation/destruction?

mnemonist's implementation of lru cache does not allocate nor destroy objects to work at all. But to be able to handle deletion, it relies on a stack of unused pointers. It has a small performance and memory impact which is why the library packs the LRUCacheWithDelete class separately so people who don't need deletions don't have to pay the cost.

This issue is a reminder to me to consider a technique I use sometimes to allow for O(1) deletion in an unordered array to see if it could replace the stack of unused pointers. The idea is that if you need to delete i.e. index 3 of an unordered array, you just need to swap its item with the one in the back, then pop it.

I have an intuition it could work for the cache's deletion but I need time to think thoroughly about it and did not find the time yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants