RcLite: small, fast, and memory-friendly reference counting

Crates.io Documentation MIT licensed Apache 2 licensed

RcLite is a lightweight reference-counting solution for Rust that serves as an alternative to the standard library's reference-counting. It offers both multi-threaded and single-threaded reference counting options with improved performance and reduced memory overhead, boasting at least 50% and up to 100% decrease in memory usage compared to the standard library reference counting. RcLite is a suitable option when weak references are not necessary and optimizing for performance and memory usage is a priority.

Why use RcLite?

Why not use RcLite?

Comparison

| | rclite::{Arc,Rc} | std::*::{Arc,Rc} | | -------------------------- | :--------------: | :---------------: | | Overhead in 64-bit systems | 4 bytes | 16 bytes | | Overhead in 32-bit systems | 4 bytes | 8 bytes | | Overhead in 16-bit systems | 2 bytes | 4 bytes | | Weak References | ❌ | ✅ | | DST Support | ❌ | ✅ |

In 64-bit systems, RcLite has an advantage over the standard library's Arc as it can utilize the memory padding area, using only 4 bytes to store the counter. This results in a reduction in memory usage, as there is less memory waste on padding. However, in situations where there is not enough padding available in the structure, RcLite will have an overhead of 8 bytes, which is still half of the standard library's overhead.

For instance, in 64-bit systems, Rc<u32> and Arc<u32> allocate the same amount of memory as Box<u32>, since the Box<u32> allocation will be padded to u64 by the allocator.

In 32-bit and 16-bit systems, the overhead of the RcLite will be 50% of the standard library.

RcLite's structure is similar to a Box<(T,counter)>, where the counter is stored after the data, as opposed to being the first field in the standard library. This eliminates the need for pointer calculation when accessing the data, but also restricts RcLite from supporting DSTs.