Qring: Fast, lock-free SPSC ring buffer with slice batching

Hey everyone! I recently published qring, a lightweight, zero-allocation, lock-free ring buffer with #![no_std] rust.

I'm sharing it here to get feedback about my code and show the areas to improve the efficiency of the implementation.

Key Architectural Details

  • SPSC Queue (for now): Implemented Single-Producer Single-Consumer for now. Support for MPSC, SPMC, and MPMC topologies are currently in development.

  • Slice Batching (pop_slice, push_exact): Allows moving chunks of data at once instead of doing single-element updations, reducing atomic synchronization overhead during bulk transfers.

  • no_std Ready: Runs on bare-metal and embedded systems without requiring a dynamic memory allocator. Focuses primarily to get as fast as it could.

  • Cache-Aligned (#[repr(align(64))]): Producer and consumer state sit on separate cache lines to prevent false sharing across CPU cores.

  • Strict Atomics: Built around explicit Acquire/Release memory orderings for lock-free safety without unnecessary CPU fences.

Quick Example

Rust

use qring::spsc::SpscQueue;

fn main() {
    // Split into producer/consumer handles (capacity: 1024)
    let (mut producer, mut consumer) = SpscQueue::<u8, 1024>::split();

    // Push batch data efficiently
    let data = [1, 2, 3, 4, 5];
    let _ = producer.push_exact(&data);

    // Pop straight into a slice
    let mut read_buf = [0u8; 5];
    let popped = consumer.pop_slice(&mut read_buf); // returns the count of popped elements

    assert_eq!(popped, 5);
    assert_eq!(read_buf, [1, 2, 3, 4, 5]);
}

Looking for Feedback

Since it is my first time in no_std rust, i would like some feedback from the community about the implementation, and share how useful it would be in real world applications.

Links

If you find qring interesting or useful, feel free to star the repository on GitHub—it really helps with visibility! Looking forward to hear your thoughts and suggestions.

I'm curious why your GitHub URL is https://www.google.com/search?q=https://github.com/sham-404/qring. It will hurt visibility within China (and wherever Google is blocked). :slight_smile:

Edit: the crates.io URL is also googlified

Most likely done by Gemini: Links getting wrapped with Google Search. - Gemini Apps Community

Hi sham-403, copy-pasting AI-written text is not allowed here. We would rather read text written by yourself. (And sorry if I get you wrong.)

(Maybe it will be better to have the rules in the guidelines as well, even though it won't reduce AI-generated posts if LLM bots don't read it.)

True it is AI generated. My bad :(. I just wanted to automate the writing that's it. Anyway I will edit it completely as soon as possible. Thanks for the info