loon is a lightweight, header-only C++ library designed for low memory footprint, low latency, and maximum performance. It provides optimized data structures that outperform standard STL counterparts while maintaining familiar interfaces.
Perfect for HFT, gaming, embedded systems, and real-time processing.
| Feature | Description |
|---|---|
| Zero-Cost Abstractions | Header-only, no external dependencies |
| STL-Compliant | Drop-in replacements with familiar APIs |
| Cache-Efficient | Optimized memory layout, contiguous storage |
| Low Latency | No dynamic allocation on critical paths |
| High Performance | Up to 3-4x faster than std:: alternatives |
| Structure | Header | Description | Performance |
|---|---|---|---|
| RingBuffer | loon/ring_buffer.hpp |
Fixed-size circular queue | 3.2x faster than std::queue |
| SpscQueue | loon/spsc.hpp |
Lock-free single-producer single-consumer queue | 18.7x faster than mutex queue |
| LRU Cache | loon/lru.hpp |
Least Recently Used cache | O(1) get/put |
| RedisList | loon/redis_list.hpp |
Redis-style doubly-linked list | O(1) push/pop |
| Structure | push | pop | get | put | front/back |
|---|---|---|---|---|---|
| RingBuffer | O(1) | O(1) | - | - | O(1) |
| SpscQueue | O(1) | O(1) | - | - | - |
| LRU Cache | - | - | O(1) | O(1) | - |
| RedisList | O(1) | O(1) | - | - | O(1) |
| Benchmark | loon | std/mutex | Speedup |
|---|---|---|---|
| RingBuffer round-trip (16B) | 1.9 ns | 6.1 ns | 3.2x |
| SpscQueue interleaved | 2.40 ns | 44.9 ns | 18.7x |
| SpscQueue producer/consumer | 485M ops/s | 26M ops/s | 19.5x |
| LRU Cache get (hit) | 15 ns | - | 67M ops/s |
| LRU Cache exists | 7.8 ns | - | 130M ops/s |
| RedisList push/pop | 3.6 ns | 78.5 ns | 22x vs std::list |
See full benchmarks for detailed results.
# conanfile.txt
[requires]
loon/0.2.0# conanfile.py
def requirements(self):
self.requires("loon/0.2.0")Copy the include/loon directory to your project and add it to your include path.
find_package(loon REQUIRED)
target_link_libraries(your_target PRIVATE loon::loon)#include <loon/ring_buffer.hpp>
loon::RingBuffer<int, 1024> buffer; // fixed capacity, reject when full
loon::RingBuffer<int, 1024> ring(true); // override oldest when full
buffer.push(42);
auto val = buffer.pop(); // std::optional<int>
buffer.front(); // peek without removing#include <loon/spsc.hpp>
loon::SpscQueue<int, 1024> queue;
// Producer thread
queue.push(42);
// Consumer thread
int value;
if (queue.pop(value)) {
// use value
}#include <loon/lru.hpp>
loon::LRU<int, std::string> cache(100); // capacity of 100
cache.put(1, "hello");
auto val = cache.get(1); // std::optional<std::reference_wrapper<V>>
if (val) {
std::cout << val->get(); // "hello"
}#include <loon/redis_list.hpp>
loon::RedisList<int> list;
list.lpush(1); // push front
list.rpush(2); // push back
auto val = list.lpop(); // pop front
auto range = list.lrange(0, -1); // get all (supports negative indices)- C++23 compatible compiler (GCC 13+, Clang 14+)
- CMake 3.20+
- Conan 2.x
make conan-setup # one-time setup
make deps # install dependencies
make build # build and run tests
make package # create Conan packagemake help # show all targets
make bench # run benchmarks
make coverage # generate coverage report
make docs-serve # serve documentation locally
make format # apply clang-formatFull documentation available at jsrivaya.github.io/loon
MIT License - see LICENSE for details.