Client was trying to estimate size of the next metric before actually producing
it to guess whether next metric is going to overflow the buffer, which has never
been easy nor precise.
Refactor that code to always append metric first, and check for overflow next.
When overflow happens, slice part before overflow for deliver and save tail to
be initial content of the next buffer.
The price is extra 1K added to the capacity of each buffer to avoid extra allocation
on overflow.
Client was trying to estimate size of the next metric before actually producing it to guess whether next metric is going to overflow the buffer, which has never been easy nor precise.
Refactor that code to always append metric first, and check for overflow next. When overflow happens, slice part before overflow for deliver and save tail to be initial content of the next buffer.
The price is extra 1K added to the capacity of each buffer to avoid extra allocation on overflow.