Go Runtime Performance

Correct behavior, explicit ownership, then measured allocation and time. Build a bounded request handler and a byte arena.

1 / 6

Byte boundaries

GET /health HTTP/1.1\r\n\r\n consumes 24 bytes; response body has 2 bytes. A following request stays in req[24:]. Incomplete input and short destination consume zero. Parsing aliases must be finished before input reuse.

2 / 6

Prove the allocation fits

With off3/capacity16, test n≤13 before adding off+n. Aligned(4,8) pads5, reserves[8,12), leaves4. A failed aligned request must consume no padding. Alignment refers to the buffer index.

3 / 6

Reset changes ownership

Old slice cat → Reset → new reservation dog: old slice now also reads dog. Reset does not zero or free backing storage. A lock around allocation alone cannot protect readers from reset.

4 / 6

Interpret the measurement

120 ns/op,64 B/op,1 alloc/op versus 145 ns/op,0 B/op,0 allocs/op: allocation improved; measured time did not. ns/op is not p99; B/op is not retained heap. Check benchmark success, setup boundaries and compiler version.

5 / 6

Runtime tradeoffs and transfer

GOMEMLIMIT is soft runtime accounting, not an RSS hard cap. Retained aliases can keep large buffers live despite zero allocations. Design when an asynchronous consumer releases an arena generation; then measure one change.

6 / 6
←/→ or click edges to navigate · ? help · N notes · F fullscreen