A GC-less, fast, generic LRU hashmap library for Go with optional locking, sharding, eviction, and expiration.
FreeLRU is a Go library that implements a high-performance, GC-less LRU (Least Recently Used) hashmap for caching. It solves the problem of garbage collection overhead in long-running applications with large caches by using a contiguous memory layout and Go generics for type safety. The library provides single-threaded and thread-safe variants optimized for different concurrency levels.
Go developers building performance-sensitive applications that require efficient in-memory caching, such as web servers, data processing pipelines, or real-time systems where low latency and minimal GC pauses are critical.
Developers choose FreeLRU for its exceptional speed, zero-allocation design for non-pointer types, and flexibility in concurrency models. It outperforms many popular Go caching libraries in benchmarks while offering a simple API and configurable memory overcommitment to tune performance.
FreeLRU is a high-performance LRU (Least Recently Used) caching library for Go designed to eliminate garbage collection overhead and provide type safety through generics. It offers multiple implementations tailored for different concurrency needs, from single-threaded to high-concurrency environments.
LRU (single-threaded), SyncedLRU (low-concurrency), and ShardedLRU (high-concurrency) implementations.LRU and SyncedLRU use exact LRU algorithms; ShardedLRU uses an approximate algorithm for scalability.FreeLRU prioritizes performance and low GC overhead by merging hashmap and ringbuffer into a contiguous array, ensuring memory locality and minimizing cache misses. It emphasizes simplicity in API design to ease migration from other LRU implementations.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses a contiguous array to eliminate heap allocations, achieving zero allocations per operation in benchmarks and reducing GC pauses for long-running applications.
Leverages Go generics for compile-time type checking and zero runtime allocations for non-pointer types, ensuring both safety and efficiency as highlighted in the README.
Offers SyncedLRU for low concurrency and ShardedLRU for high concurrency, with benchmarks showing ShardedLRU outperforming competitors like Ristretto in parallel tests.
Allows allocating extra hashtable memory to reduce collisions, improving speed by up to 20% in performance tests, as demonstrated in the benchmarks section.
Callers must provide their own hash function for keys, adding setup overhead and potential for performance issues if suboptimal hashes are chosen, as admitted in the README.
Supports only LRU eviction without built-in TTL or other policies, missing common caching features that might be needed for applications with complex expiration logic.
The SyncedLRU implementation suffers from significant lock contention in high-concurrency environments, as benchmarks show it performs poorly compared to sharded alternatives.