-
Notifications
You must be signed in to change notification settings - Fork 148
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
ref(lru-cache): Change lru cache crate to avoid vulnerable dependency #478
Conversation
Some quick and dirty benchmarks for the caches and lru crates for the LRU cache.
This makes use the the facilities to compare two functions and also uses iter_batches to handle setup and dropping correctly. The results are widely different! The differences between both implementations are much muchness really, not much to go either way.
The performance is pretty similar and we don't use any features of the bigger crate.
This makes sure it no longer shows up in cargo-audit.
iroh-p2p/benches/lru_cache.rs
Outdated
//! The bench functions for the `caches` crate are commented out in order not to require a | ||
//! dependency on the crate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove these entirely, and reposition this PR as swapping out the caches
crate for lru
, but also comes with the upside of having a benchmark
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vote we remove the commented out caches bench entirely, then this is good-to-go
//! # Running the benchmarks | ||
//! | ||
//! Install `cargo-criterion`: | ||
//! | ||
//! ```shell | ||
//! cargo install cargo-criterion | ||
//! ``` | ||
//! | ||
//! Run the benchmarks: | ||
//! | ||
//! ```shell | ||
//! cargo criterion -p iroh-p2p | ||
//! ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ran these locally, works! If we add more benchmarks that use this pattern we can define an xtask
to run them. I'd skip it for this one, as we're mainly hanging on to this bench for future use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused, you can just run the benchmarks with cargo bench
if the config is setup correctly: https://github.com/bheisler/criterion.rs#quickstart
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, i forgot that worked by the time i was finished: #483
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the removal of the old cache bench, works for me!
use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; | ||
use libp2p::PeerId; | ||
|
||
// The size of the cache to make. Taken from behaviour::peer_manager::DEFAULT_BAD_PEER_CAP. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be ///
Change the LRU cache from the caches crate to the lru crate. This crate is much simpler and does not depend on a vulnerable version of the time crate, resolving our cargo-audit issues.
A benchmark is included showing our use of the LRU cache to have no notable performance difference between both crates.
Closes n0-computer/beetle#131