Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2025

Always reuse buffers in bsonrw.valueWriter

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Unknown Unknown
    • 1.6.0
    • 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.

            Assignee:
            matt.dale@mongodb.com Matt Dale
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: