Cloudflare

How we saved 100 terabytes of memory by optimizing 1.1.1.1’s DNS cache

Aug 27, 2026Sebastiaan Neuteboom
How we saved 100 terabytes of memory by optimizing 1.1.1.1’s DNS cache
SummaryAI, from the source post

The post details five specific memory optimization techniques applied to the 1.1.1.1 DNS cache: 1. Replacing `Vec<T>` and `String` with `Box<[T]>` and `Box<str>` to eliminate capacity fields and excess heap allocation. 2. Consolidating answer, authority, and additional sections into a single list with offsets, reducing pointer and length overhead. 3. Inferring record owners when identical to the queried domain to avoid redundant storage. 4. Boxing larger enum variants for `RecordData` to reduce wasted space from padding. 5. Packing boolean fields into a bitflag to reduce surrounding padding. The post also describes the benchmarking methodology used to measure memory usage, insert throughput, and lookup latency.

More from the Cache Management trail