一个针对高并发系统优化的LRU哈希表实现项目在Hacker News上公开,该项目采用分片架构、预分配内存和自定义自旋锁等技术方案 [1]。与标准库实现相比,该项目在多核、NUMA架构上的吞吐量提升超过14倍,并实现了亚微秒级的尾延迟 [1]。项目采用32位数组索引替代64位指针以减半内存开销,分片数量动态扩展到CPU核心数的32倍,并通过预分配Mega-Block平面数组避免堆碎片 [1]。
该实现支持零运行时分配,具备NUMA感知内存分配能力,可跨物理CPU插槽分布数据 [1]。项目提供用户态和内核态两种实现版本,支持Windows、Linux和macOS多个平台部署 [1]。设计中采用了自定义TTAS自旋锁和指数退避策略,并支持懒惰LRU晋升特性,该特性可额外提升约20%的吞吐量 [1]。插入、查找、删除操作均保持O(1)的平均时间复杂度 [1]。
该项目主要应用于高频交易、存储缓存、实时网络路由、内核驱动和高吞吐Web服务器等场景 [1],并采用Apache License 2.0开源许可 [1]。
An open-source LRU hash table implementation optimized for high-concurrency systems programming has demonstrated significant performance gains over standard library alternatives [1]. The project employs sharded architecture, pre-allocated memory, and custom spinlock mechanisms to achieve throughput improvements exceeding 14 times that of std::shared_mutex implementations on multi-core and NUMA architectures, while maintaining sub-microsecond tail latencies [1].
The design incorporates several key optimizations to minimize latency and memory overhead [1]. Memory is pre-allocated in mega-block flat arrays to eliminate heap fragmentation, and 32-bit array indices replace 64-bit pointers, effectively halving memory consumption [1]. The implementation supports zero runtime allocations and features NUMA-aware memory distribution across physical CPU sockets [1]. Sharding automatically scales to 32 times the number of CPU cores, with users able to configure custom TTAS spinlocks and exponential backoff strategies [1]. The system also supports lazy LRU promotion, which can boost throughput by approximately 20 percent [1]. All insertion, lookup, and deletion operations maintain O(1) average-case time complexity [1].
The project targets demanding real-world applications including high-frequency trading systems, storage caches, real-time network routing, kernel drivers, and high-throughput web servers [1]. It provides implementations for both user-space and kernel-space environments across multiple platforms—Windows, Linux, and macOS—enabling flexible deployment [1]. The codebase is distributed under the Apache License 2.0 [1].