agerasev / ringbuf

Lock-free SPSC FIFO ring buffer with direct access to inner data
https://crates.io/crates/ringbuf
Apache License 2.0
287 stars 29 forks source link

Performance vs other crates? #8

Open TheButlah opened 3 years ago

TheButlah commented 3 years ago

A basic performance comparison would be great to compare against other rust ringbuffers, as well as crossbeam channel.

mgeier commented 3 years ago

See also https://github.com/mgeier/rtrb/issues/39.

agerasev commented 3 years ago

Hi, thank you for being interested in this crate!

Honestly speaking, the performance wasn't the main goal of the crate and I haven't focused on it heavily. I created that crate just to have at least some implementation of ring buffer being light-weight and with direct access to underlying memory. And I'm glad to see that now there is a variety of a ring buffer implementations to choose from.

About your question - @mgeier made a nice comparison and according to it rtrb seems to be a better option.

It's interesting to find out where 3x performance difference come from. Maybe in near future I will find some time to investigate this and to apply some optimizations.

mgeier commented 3 years ago

It's interesting to find out where 3x performance difference come from.

I guess a part of it comes from false sharing of the head and tail indices as suggested in #7.

https://github.com/agerasev/ringbuf/issues/7#issuecomment-666339687 mentions another potential optimization by trying to read the atomic indices less often.