Skip to content

Blog

Bytes You Can Type

A binary blob, rewritten as one big number in an alphabet a human can actually type.

Sooner or later a pile of bytes has to face a human: an id in a URL, a hash in a log line, a key read off a screen and typed into another. Hex is twice too long, base64 carries characters that break in URLs and look alike on paper. The tenth familiar makes bytes typeable by treating the whole blob as one enormous number and rewriting it in a friendlier base.

Packing a UUID

Shrinking a 128-bit id by noticing how much of it is not random.

A UUID is sixteen bytes, and we treat them as sixteen bytes of pure randomness. A time-based UUID is nothing of the sort: it is a timestamp and a clock and a machine id wearing a hex costume, and a stream of them from one server repeats itself enormously. The ninth familiar reads that structure and packs the same id into eight bytes, decoded in nanoseconds and sortable by time.

Sixteen Bytes Too Far

A streaming HTTP parser that never copies, and the one place it read past the buffer.

Bytes arrive off a socket in whatever sizes the network felt like: a whole request in one read, or one byte at a time, or a header split down the middle. A streaming parser has to produce the same result regardless, without copying and without ever reading a byte it was not handed. The eighth familiar does exactly that, except for the one line where it reached sixteen bytes past the end of the buffer, and only the sanitizer noticed.

The Line You Usually Cancel

Arming a 'this is taking too long' log on every operation, and paying only for the one that fires.

You want to know which operations are slow, but logging every operation is noise you pay for on the hot path. So you invert it: arm a 'log this if it is still running in 200 ms' line on every single operation, and cancel it, free, the instant the operation finishes, which is almost always. The seventh familiar logs the exceptions by speculating on everything, and it is the reason the sparse wheel was built at all.