Replace channel with crossbeam-channel?


#1

They are an improvement in pretty much all aspects: ergonomics, flexibility, features, performance. - https://github.com/crossbeam-rs/crossbeam-channel

Sorry if this is a stupid question, but why haven’t they replaced libstd’s implementation of channels with this awesome library yet?


#2

@stjepang might know :slight_smile:


#3

This is a good question. There was some discussion on it in the issue tracker: https://github.com/rust-lang/rust/issues/27800

The main obstacle to moving crossbeam-channel into the standard library is that it’s incredibly complex. In addition to having around 5K lines of code, it also depends on crossbeam-epoch, which is a type of garbage collection mechanism. It’s just not going to happen.

Instead, we might deprecate std::sync::mpsc, but we’ll see. The standard library channels have grown to be very complex, too. They are a real gem of engineering, but unfortunately have several core design issues which would require a ton of effort to fix. For example, sync_channel scales poorly due to high mutex contention, it’s basically impossible to make Sender implement Sync, and select! has been nightly-only for years, mostly due to complexity and unsatisfactory interface. Frankly, I believe it’s easier to just start from scratch than fix std::sync::mpsc, which is why we have crossbeam-channel now.

By the way, I’m about to release a new version of crossbeam-channel (new Go-like API, performance improvements, very simple select! macro) very soon, so you might want to keep an eye on that. :slight_smile:
PR: https://github.com/crossbeam-rs/crossbeam-channel/pull/41


#4

Just wanted to say thanks for all your great work in the crossbeam space! :+1: