External Publication
Visit Post

Idea : Lock Free STD Collection

Rust Internals [Unofficial] March 5, 2026
Source
fuji-184: > Lock free performance is generally superior Is it? Lock-free implies these collections are supposed be mutably shared across threads, but mutable sharing itself can be a source of performance problems. No matter how you do locking (or not - see false sharing), you can still have performance penalty from writing to memory cached across cores. There are many possible trade-offs for mutably-shared collections, and I wouldn't say they're faster, but rather you can choose which workloads are least slowed down by the sharing. You can make collections that tolerate higher concurrency when writing or appending, but this usually comes at a cost of slower reads and pointer chasing. Or you can design for mostly-immutable collections that only need an occasional write, by using optimistic locking (and still call it lock-free because it uses spinlocks or swaps pointers to copies). And there's the special case of wait-free (for guaranteed latency, usually at the cost of everything else), and a subset of that which is signal-safe where you literally can't use locks. It's not a "generally superior" upgrade. It's a bunch of tricky problems with different costs and downsides, highly dependent on the workload. If you make some middle-of-the road universal collection, it may end up being inferior in every workload compared to more specialized implementations. What's the use-case? What do you need interoperability with, and why by sharing a specific collection type and not a channel, callback, or an implementation hidden behind a trait?

Discussion in the ATmosphere

Loading comments...