smol-rs / async-broadcast

Async broadcast channels
Apache License 2.0
151 stars 26 forks source link

use `Mutex` instead of `RwLock` for securing the inner data #67

Closed hozan23 closed 1 week ago

hozan23 commented 1 week ago

This addresses the issue #42

The use of RwLock is typically used when there is a need for multiple readers and infrequent writers, as RwLock allows multiple concurrent readers or a single writer. However, most functions were using the write() method, while the read() method was rarely used.

hozan23 commented 1 week ago

@zeenix thanks, I updated the commit message.

fogti commented 1 week ago

do we have some benchmarks to check that this doesn't cause sigificant performance regressions?

zeenix commented 1 week ago

do we have some benchmarks to check that this doesn't cause sigificant performance regressions?

No but is there a reason we'd suspect so? 🤔

hozan23 commented 1 week ago

@fogti In theory, it should not cause any performance regressions. #42 didn't mention any performance issues with using rwlock, but as far as I know, the only issue with rwlock is writer starvation, whereas a mutex cannot have this issue. However, I agree that we do need some benchmarks to check the performance. I will do it when I have time.

fogti commented 1 week ago

@hozan23 tbh, the link to the introduction of rwlock suffices for me.