Optimize current ByteBuffer access in ByteBufferBsonOutput

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Unknown
    • 5.5.0
    • Affects Version/s: None
    • Component/s: Performance
    • None
    • Java Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      The current implementation of ByteBufferBsonOutput accesses the active ByteBuf on each write via bufferList.get(index), introducing unnecessary overhead and limiting JIT inlining.

      We can optimize this by caching the current buffer in a currentByteBuffer field and updating it only when switching buffers.

      Rationale:

      • Accessing a field is just a pointer dereference — extremely cheap, especially once JIT-optimized.
      • bufferList.get(index) involves bounds checking and method invocation, even for ArrayList.
      • While individually cheap, this overhead adds up in tight write loops under high throughput.

              Assignee:
              Slav Babanin
              Reporter:
              Slav Babanin
              Maxim Katcharov, Nabil Hachicha
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: