-
Type: Improvement
-
Resolution: Done
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
Currently, a bsonrw.valueWriter will use a new byte slice as the write buffer for each document written if one is passed in as the writer (if it is a SliceWriter). The result is that the write buffer capacity must be grown many times, each resulting in an allocate-then-copy operation. Instead, we should reuse the write buffer for every document written, only allocating a new byte slice when flushing the full document from the buffer (or when the write buffer needs to grow).
In the attached memory profile, observe that >75% of the allocations are in the bsoncore.Append* functions which append to a byte slice buffer provided by bsonrw.valueWriter. We should expect very few allocations in the bsoncore.Append* functions once the buffer is grown the first time.
- related to
-
GODRIVER-1670 Use buffer pooling and copying return values to reduce memory allocation
- Closed