maidsafe / lru_time_cache

LRU cache settable via size or time to live
BSD 3-Clause "New" or "Revised" License
104 stars 46 forks source link

Various optimization ideas #107

Closed tafia closed 6 years ago

tafia commented 6 years ago

This PR is not necessarily meant to be merged as is, it is rather several optimization ideas for the lru_cache.

I couldn't install rustfmt-nightly 0.8.2, so I expect some breaks, I'll fix them later.

maidsafe-highfive commented 6 years ago

Thanks for the pull request, and welcome! The MaidSafe team is excited to review your changes, and you should hear from @Fraser999 (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see CONTRIBUTOR.md for more information.

tafia commented 6 years ago

Also, any reason to use a BTreeMap instead of a HashMap (which could probably be faster?). I understand that it requires the Key to be PartialEq + Hash instead of just Ord, but this doesn't really looks like an issue in practice.

Fraser999 commented 6 years ago

Also, any reason to use a BTreeMap instead of a HashMap (which could probably be faster?). I understand that it requires the Key to be PartialEq + Hash instead of just Ord, but this doesn't really looks like an issue in practice.

That's down to our requirement to have reproducible tests in our crates which depend on this one. If we use a HashMap we lose the ability to rerun a failing test with a given RNG seed and get the same failure repeatedly.

This requirement may change in the future, or we may want a solution where we use a container which is optimised (like HashMap) for production use, but can be made deterministic via a feature for the case of reproducible tests. Not sure how that'll pan out, but we've largely been focused on code correctness for now, with optimisations taking a back seat at the moment.

tafia commented 6 years ago

Thanks for the review both of you. I had to leave yesterday so I couldn't answer you.

pierrechevalier83 commented 6 years ago

Thanks for this new contribution, @tafia :smile: