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

chore: use parking_lot instead of std::sync for locks #11289

Merged
merged 1 commit into from
Jul 7, 2021

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Jul 5, 2021

We're already using parking_lot extensively, but transitvely in dependencies. For example, parking_lot is used by tokio instead of std::sync for locks as a performance optimization. It might be good for us to also use it as it uses less memory, is faster, and has more features (I've used it in my projects and the API is a bit better).

Relates to #3429.

From https://crates.io/crates/parking_lot

When tested on x86_64 Linux, parking_lot::Mutex was found to be 1.5x faster than std::sync::Mutex when uncontended, and up to 5x faster when contended from multiple threads. The numbers for RwLock vary depending on the number of reader and writer threads, but are almost always faster than the standard library RwLock, and even up to 50x faster in some cases.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

If benchmarks are favorable then LGTM.

@dsherret dsherret marked this pull request as ready for review July 6, 2021 14:02
@dsherret
Copy link
Member Author

dsherret commented Jul 6, 2021

@bartlomieju benchmarks look basically the same. I don't think this change affects much in the benchmarks as there aren't any of these locks used in any hot paths that I can see, though it would be nicer to use.

This PR is more a "might be nice to have"

@dsherret dsherret requested a review from ry July 6, 2021 14:34
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

I’m skeptical about using non-std functionality for performance reasons, when the benefit hasn’t been demonstrated.

I’m not necessarily against it but deferring to @piscisaureus for review.

@ry ry requested a review from piscisaureus July 6, 2021 15:40
@dsherret
Copy link
Member Author

dsherret commented Jul 6, 2021

Makes sense. I suspect if we turned off the parking_lot feature in tokio we would notice a difference, but yeah after running the benchmarks I see no performance benefit of this PR. The API is better and this PR makes us use parking_lot more consistently though. Perhaps some future code might benefit from it being faster. I don't have strong feelings though.

@dsherret dsherret merged commit 7fc0e8e into denoland:main Jul 7, 2021
@dsherret dsherret deleted the parking-lot branch July 7, 2021 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants