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

ref(lru-cache): Change lru cache crate to avoid vulnerable dependency #478

Merged
merged 6 commits into from
Nov 9, 2022

Conversation

flub
Copy link
Contributor

@flub flub commented Nov 8, 2022

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

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.
@flub flub requested a review from rklaehn November 8, 2022 15:58
@flub flub marked this pull request as draft November 9, 2022 11:35
This makes sure it no longer shows up in cargo-audit.
@flub flub marked this pull request as ready for review November 9, 2022 12:04
Comment on lines 22 to 23
//! The bench functions for the `caches` crate are commented out in order not to require a
//! dependency on the crate.
Copy link
Member

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

Copy link
Member

@b5 b5 left a 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

Comment on lines +6 to +18
//! # Running the benchmarks
//!
//! Install `cargo-criterion`:
//!
//! ```shell
//! cargo install cargo-criterion
//! ```
//!
//! Run the benchmarks:
//!
//! ```shell
//! cargo criterion -p iroh-p2p
//! ```
Copy link
Member

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

Copy link
Contributor

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

Copy link
Contributor Author

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

@ramfox ramfox added the bug Something isn't working label Nov 9, 2022
@ramfox ramfox added this to the v0.1.1 milestone Nov 9, 2022
@ramfox ramfox assigned ramfox and flub and unassigned ramfox Nov 9, 2022
rklaehn
rklaehn previously approved these changes Nov 9, 2022
Copy link
Contributor

@rklaehn rklaehn left a 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!

@flub flub merged commit fb53f8f into main Nov 9, 2022
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

should be ///

@flub flub deleted the flub/bench-lru-cache branch November 22, 2022 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix cargo audit errors
5 participants