How we saved 100 terabytes of memory by optimizing 1.1.1.1’s DNS cache
Summary
Cloudflare explains how it saved 100 TB of memory in its 1.1.1.1 DNS cache by a series of memory-layout and data-structure optimizations. The changes reduce per-entry footprint by over 50%, from 953 bytes to 420 bytes, and cut allocations, while boosting insert throughput by 43% and decreasing lookup latency by 19%. The post also details moving from Vec and String to Box<[T]> and Box<str>, storing record data in a compact wire-format buffer, and other strategies to improve memory locality and performance.