Skip to content

Blog

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.

The Long Division

An arbitrary-precision integer, and why division is the part everyone gets wrong.

Sixty-four bits runs out. A 256-bit hash, a base conversion, a counter that must never wrap, and suddenly you want a number with no ceiling that still reads like a * b + c. The sixth familiar is that number. Addition is easy and multiplication has a famous trick, but division is the operation that separates a bignum that works from one that is wrong on inputs no random test will ever find, and you will never know which.

The Planet as a Prefix

Turning the whole Earth into search terms a plain text index can answer.

'Find documents within 5 km of here' is not a text query, and you cannot scan your way to it. The trick Xapiand uses is to turn the surface of the Earth into a hierarchy of triangles, give every point a name whose prefix is its neighborhood, and let the text index do the rest. The fifth familiar tiles a planet so a search engine that only knows words can answer questions about space.