rust-signals icon indicating copy to clipboard operation
rust-signals copied to clipboard

Question - Do the native Mutex, RwLock used affect performance ?

Open szagi3891 opened this issue 3 years ago • 4 comments

I noticed that native mutexes were used for state synchronisation use std::sync::{Arc, Weak, Mutex, RwLock }

Doesn't this affect performance ? Wouldn't it be better to use a mutex from tokio ?

szagi3891 avatar Jul 31 '22 17:07 szagi3891

You mean parking_lot? This crate is designed to be portable, it can work on any platform (including Wasm). There are various issues with parking_lot that make it not feasible right now. At least on Wasm, the stdlib Mutexes are much faster.

There have been substantial efforts in integrating parking_lot into the stdlib:

https://github.com/rust-lang/rust/pull/56410 https://github.com/rust-lang/rust/issues/93740

Most of the performance improvements seem to have already been merged, so I'm curious whether parking_lot is actually faster or not.

Pauan avatar Jul 31 '22 23:07 Pauan

You mean parking_lot? This crate is designed to be portable, it can work on any platform (including Wasm). There are various issues with parking_lot that make it not feasible right now. At least on Wasm, the stdlib Mutexes are much faster.

There have been substantial efforts in integrating parking_lot into the stdlib:

rust-lang/rust#56410 rust-lang/rust#93740

Most of the performance improvements seem to have already been merged, so I'm curious whether parking_lot is actually faster or not.

I don't know whether the std mutex is faster than parking_lot either. I came from here when I decided to use spin at first. And now I think the std mutex and parking_lot would be better for most synchronization cases.

But between std mutex and parking_lot, I think std mutex should be preferred at first unless you have an extremely time-efficiency sensitive case.

dbsxdbsx avatar Sep 25 '22 07:09 dbsxdbsx

While I do remember parking_lot speeds up my toy nbody simulation a lot 5 years ago, on modern CPUs (I tested apple M1, Zen3+), I really see no performance gain from parking_lot (or even worse, parking_lot has a large negative performance impact).

SchrodingerZhu avatar Aug 22 '23 02:08 SchrodingerZhu

While I do remember parking_lot speeds up my toy nbody simulation a lot 5 years ago, on modern CPUs (I tested apple M1, Zen3+), I really see no performance gain from parking_lot (or even worse, parking_lot has a large negative performance impact).

Things may change a lot in the past 5 years. I do think that trying the built-in one is a good practice at first.

dbsxdbsx avatar Aug 22 '23 09:08 dbsxdbsx