Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Performance Comparison of Mutex, RWLock and Ato...

Performance Comparison of Mutex, RWLock and Atomic types in Rust

Mitsunori Komatsu

February 26, 2023
Tweet

More Decks by Mitsunori Komatsu

Other Decks in Technology

Transcript

  1. About me Mitsunori Komatsu, 
 Software engineer Started learning Rust

    recently (7 months ago) Contributed a small feature to Rust (https:// github.com/rust-lang/rust/pull/33976) https://github.com/komamitsu/td-client-rust https://github.com/komamitsu/treasuredata_fdw
  2. Mutable Types in Arc (Arc uses atomic reference count) Mutex

    Mutual Exclusion Lock Can contain Send RWLock Read: Shared Lock Write: Exclusive Lock Can contain Send + Sync Atomic types Atomic counter - We can update these types in multi-threads
  3. Summary The performance of RWLock expectedly degrades when the number

    of writes increases The performance of Mutex doesn't significantly change even under write heavy operations. Also, it’s really optimized on Linux AtomicUsize is always really fast. Use it if you want just a counter