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

Improve pooled buffer reuse pattern

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • Go Drivers

      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).

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

              Created:
              Updated: