arthurprs / quick-cache

Lightweight and high performance concurrent cache
MIT License
177 stars 11 forks source link

Consider making dependency on `parking_lot` optional #5

Closed AlexTMjugador closed 1 year ago

AlexTMjugador commented 1 year ago

It is conventional wisdom among the Rust community that parking_lot used to provide an implementation of RwLock that was better than std::sync::RwLock:

However, with the release of Rust 1.62, the std::sync::RwLock implementation was overhauled. The changes are described in detail at https://github.com/rust-lang/rust/issues/93740, its release announcement on the Rust blog, and the resources those pages link to.

As it was discussed in the Rust language forum, I believe that the choice between parking_lot and std::sync::RwLock is less clear-cut now than it was before:

There are more arguments for and against both std's and parking_lot locks, but I think the points above suffice to grasp that adding the ability to toggle quick-cache's dependency on parking_lot may be a good idea. Moreover, it is a stated goal of quick-cache to have a "small dependency tree", so making dependencies optional increases the appeal of this crate with respect to that goal.

As an experiment, I did a quick patch to https://github.com/arthurprs/quick-cache/commit/5dc07e188751ef9f04242ec2d28f398417a1c553 to swap parking_lot's RwLock with std::sync::RwLock and ran cargo bench before and after the change. Criterion did not find any statistically significant performance difference on a Linux system running on an Intel Core i7-12700 CPU.

I would not mind submitting a PR with this change if it is deemed appropriate for the project :heart:

arthurprs commented 1 year ago

This is a good idea. I keep defaulting to parking lot because of the historical performance benefits and avoiding the unwraps :grimacing:

I would not mind submitting a PR with this change if it is deemed appropriate for the project heart

That would be great :heart_decoration: