Context
There are some cases where the pooled buffer behavior is unexpected:
- bytes.Buffer is always initialized with at least 64 bytes. If only values smaller than half of that (32 bytes) are marshaled, buffers will never be reused because of the buffer used capacity check (see here and here).
- Anytime a small value is marshaled while marshaling some large values, that buffer is discarded if the small value is less than half the size of the large values. That means marshaling even a few small values will result in significantly reduced buffer reuse (and more allocations).
We should find a pooled buffer management strategy that causes less unexpected churn.
Definition of done
- Implement a pooled buffer management system based on this suggested implementation.
- Add benchmarks that cover a range of use cases, including marshaling a mix of large and small messages.
Pitfalls
- If we do it wrong, we could introduce data race bugs or increase the amount of memory that the Go Driver holds onto (similar to a memory leak).
- is related to
-
GODRIVER-3307 TestCollection/insert_many tests intermittently fail with data race panic.
- Investigating