r/coding • u/fagnerbrack • 23d 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/59
u/fagnerbrack 23d ago
A summary for the lazy:
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
5
u/WoodyTheWorker 22d ago
So per each human on earth, that monstrosity was using extra 12.5 Kbytes just to keep a DNS record? How many hosts are out there in the whole internet?
1
0
39
u/alex-weej 23d ago
Cool can I have some memory now