← ClaudeAtlas

rule-record-sizelisted

A record's size is not its payload's size. An enum is as large as its biggest variant, a growable container carries capacity it will never use, and padding is invisible in the source. Multiplied by a million rows that is real memory. Load before defining a struct, enum or cache entry that will exist in bulk.
djnsty23/claude-auto-dev · ★ 3 · DevOps & Infrastructure · score 65
Install: claude install-skill djnsty23/claude-auto-dev
# The size of a record is not the size of its data Per-record waste is the only kind that multiplies by a number nobody chose. The row count is set by traffic, not by a design decision, so a byte you did not notice is billed once per row forever. `[reported]` Cloudflare's 1.1.1.1 resolver, from a public write-up read second hand rather than from the post itself, so treat the figures as illustrative and re-derive them before quoting: roughly 250 billion cached DNS entries, where one wasted byte per entry is about 250 GB across the fleet. Four layout changes and nothing else took p99 resident memory from 9.3 GB to 5.3 GB per instance, a 43% cut, with insert throughput rising from about 625k to 900k entries per second. The reason this needs a rule rather than a code review is that every one of those four wastes is **invisible in the source**. The struct reads correctly, the types are the obvious ones, and no test can fail. Only `size_of` says anything. ## 1. Measure the record against its payload, before anything else One line, and almost nobody runs it: ```rust println!("{} bytes", std::mem::size_of::<CacheEntry>()); ``` Compare that number to the bytes you believe you are storing. A ratio above about 2 means the sections below apply. A ratio near 1 means stop reading and go do something else. Go: `unsafe.Sizeof(x)`, and `fieldalignment` in `go vet`. C and C++: `sizeof`, and `pahole` prints padding per field. Zig: `@sizeOf`. Swift: `MemoryLayout<T>.size` alongside `.str