Cloudflare frees 100 terabytes of memory in 1.1.1.1's DNS cache
Five Rust optimizations cut per-entry memory from 953 bytes to 420. The company reports insert throughput up 43% and lookup latency down 19%.
Cloudflare has detailed a set of memory optimizations to Big Pineapple, the system behind its public DNS resolver 1.1.1.1. By the company's figure, roughly 100 terabytes of memory were freed across its server fleet.
The scale explains the problem: the system holds more than 250 billion cache entries. At that size, every byte wasted per entry costs 250 gigabytes of memory in total.
All five changes are data-structure work in Rust. Replacing Vec and String fields with their Box equivalents dropped unused capacity fields, saving 64 bytes per entry on its own. Storing the answer, authority and additional sections in a single list with u16 offsets, rather than separate lists, added another 28 bytes. The record owner field is no longer stored when it matches the queried domain; it is inferred at read time. Moving large enum variants to the heap saved over 120 bytes per record for common types such as A and AAAA. Finally, record data is now kept as raw bytes in a contiguous buffer instead of parsed variants.
In total, per-entry memory fell from 953 bytes to 420 — a 56% reduction. The company says this did not come at the cost of speed: cache insert throughput rose 43% and lookup latency dropped 19%.
The write-up also lists the trade-offs. Records must now be iterated sequentially, with no random indexing. Records containing domain names still require parsing for DNS name compression. And boxing variants introduces allocator overhead and scattered heap locality.
For details see Cloudflare's blog post.