r/SoftwareEngineering • • 20d ago

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

https://blog.cloudflare.com/dns-cache-memory-optimization-1111/
39 Upvotes

5 comments sorted by

17

u/fagnerbrack 20d ago

This is a TL;DR cause time is precious:

Cloudflare's Big Pineapple platform holds over 250 billion DNS cache entries, so every byte wasted per entry costs 250 GB across the fleet. Five Rust changes cut per-entry memory by over 50% and freed about 100 TB of RAM. Insert throughput also rose 43% and lookup latency fell 19%. The team swapped Vec and String for Box<[T]> and Box<str>, dropping capacity fields and excess heap space for over 15 TB of savings. They merged three record sections into one list with u16 offsets and packed booleans into bitflags to cut padding. Records whose owner matches the queried domain now skip storing it. Boxing large enum variants like NAPTR keeps A and AAAA records from paying for 144-byte padding, at some cost in jemalloc overhead and memory locality.

If the summary seems inacurate, just downvote and I'll try to delete the comment eventually 👍
Click here for more info, I read all comments

4

u/RustOnTheEdge 19d ago

Thanks again mate, excellent summary!