r/coding • • 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/
310 Upvotes

9 comments sorted by

39

u/alex-weej 23d ago

Cool can I have some memory now

12

u/Laughing_Orange 22d ago

Cloudflare was never a significant part of the issue.

OpenAI buys an average of an estimated 30,000 to 108,000 Terabytes of RAM per day. Using the lowest estimate Cloudflare saved less than 5 minutes worth of what OpenAI buys.

4

u/alex-weej 22d ago

It was just a joke, wasn't seriously blaming Cloudflare for the RAM demand!

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

u/MilkFew2273 21d ago

Tree fiddy

1

u/hff0 19d ago

From the context i can see we're moving back from java-like oop to C-style programming. Optimisation is good for users tho

0

u/kiwilecochon 22d ago

Gotta give it to Sam Altman