Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache(blog.cloudflare.com)
904 points by TangerineDream 14 days ago | 280 comments
tl;dr: Cloudflare cut per-entry memory in 1.1.1.1's DNS cache by 56% (from 953 to 420 bytes) through five Rust-level optimizations: replacing `Vec`/`String` with `Box<[T]>`/`Box<str>`, merging record sections with offsets, dropping redundant owner names, boxing large enum variants, and storing record data in raw wire format. Across the fleet this freed ~100TB of RAM, while also boosting insert throughput 43% and cutting lookup latency 19% thanks to better memory locality and fewer allocations.
HN Discussion:
  • Endorses the ship-then-optimize development philosophy demonstrated by Cloudflare
  • Validates that systems programming and low-level memory optimization still matters
  • Shares similar personal experiences with memory optimization achievements
  • ~Suggests additional optimizations Cloudflare missed, like radix trees or inline allocation
  • Questions whether merging vectors with offsets undermines Rust's safety guarantees