Crossfire: High-Performance Lockless Spsc/mpsc/mpmc Channels for Rust
Posted2 months agoActiveabout 2 months ago
github.comTechstory
calmpositive
Debate
40/100
RustConcurrencyChannel Implementation
Key topics
Rust
Concurrency
Channel Implementation
The post shares a Rust library for high-performance lockless channels, sparking discussion on its performance, correctness, and potential use cases in concurrent programming.
Snapshot generated from the HN discussion
Discussion Activity
Active discussionFirst comment
3h
Peak period
20
Day 1
Avg / period
10.5
Comment distribution21 data points
Loading chart...
Based on 21 loaded comments
Key moments
- 01Story posted
Nov 1, 2025 at 11:07 PM EDT
2 months ago
Step 01 - 02First comment
Nov 2, 2025 at 1:57 AM EDT
3h after posting
Step 02 - 03Peak activity
20 comments in Day 1
Hottest window of the conversation
Step 03 - 04Latest activity
Nov 15, 2025 at 9:09 AM EST
about 2 months ago
Step 04
Generating AI Summary...
Analyzing up to 500 comments to identify key contributors and discussion patterns
ID: 45787571Type: storyLast synced: 11/20/2025, 7:40:50 PM
Want the full context?
Jump to the original sources
Read the primary article or dive into the live Hacker News thread when you're ready.
SPSC = Single Producer Single Consumer
MPMC = Multiple Producer Multiple Consumer
(I'll let you deduce the other abbreviations)
We read left to right, so <producer>:<consumer> is the natural order.
M = Multi
---
C = Consumer
P = Producer
[0]: https://github.com/frostyplanet/crossfire-rs/wiki#kanal [1]: https://news.ycombinator.com/item?id=45774086
Even folks who write modern go try to avoid overusing channels. It's quite common to see go codebases with few or no channels.
Of course it matters what synchronization primitives you choose, for the reasons you gave.
Thats not true. There are stackgul coroutine libraries in Rust too. I believe there's one called "may". They are admittedly not that widely used, but they are available.
here "parallel" is used in the most broad sense where you have (probably unrelated) tasks that are mostly independent for each other and run to completion. In that case "async" is an anti-pattern. So if you work more process-based that switch-based go!
Two acquires back to back are unnecessary here. In general, fetch_sub and fetch_add should give enough guarantees for this file in Relaxed. https://github.com/frostyplanet/crossfire-rs/blob/master/src...
Congest is never written to with release, so the Acquire is never used to form a release chain: https://github.com/frostyplanet/crossfire-rs/blob/dd4a646ca9...
The queue appears to close the channel twice (once per rx/tx), which is discordant with the apparent care taken with the fencing. https://github.com/frostyplanet/crossfire-rs/blob/dd4a646ca9...
The author also suggests an incorrect optimization to Tokio here which suggests a lack of understanding of what the specific guarantees given are: https://github.com/tokio-rs/tokio/pull/7622
The tests do not appear to simulate the queue in Loom, which would be a very, very good idea.
This stuff is hard. I almost certainly made a mistake in what I've written above (edit: I did!). In practice, the queue is probably fine to use, but I wouldn't be shocked if there's a heisenbug lurking in this codebase that manifests something like: it all works fine now, but in the next LLVM version an optimization pass is added which breaks it on ARM in release mode, and after that the queue yields duplicate values in a busy loop every few million reads which is only triggered on Graviton processors.
Or something. Like I said, this stuff is hard. I wrote a very detailed simulator for the Rust/C++ memory model, have implemented dozens of lockless algorithms, and I still make a mistake every time I go to write code. You need to simulate it with something like Loom to have any hope of a robust implementation.
For anyone interested in learning about Rust's memory model, I can't recommend enough Rust Atomics and Locks:
https://marabos.nl/atomics/
Loom is apparently this: https://github.com/tokio-rs/loom I've used tokio a bit in the past, but wasn't aware of that tool at all, looks really useful and probably I'm not alone in never hearing about it before. Any tips&tricks or gotchas with it one should know beforehand?
https://github.com/JCTools/JCTools