Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-5846

Optimize current ByteBuffer access in ByteBufferBsonOutput

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Java Drivers
    • 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@mongodb.com Slav Babanin
            Reporter:
            slav.babanin@mongodb.com Slav Babanin
            Maxim Katcharov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: