Avoid Double Byte Reversal in NettyByteBuf

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Performance
    • None
    • None
    • Java Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      In NettyByteBuf, we currently call order(LITTLE_ENDIAN) on a Netty ByteBuf, which wraps the original Big Endian buffer in a SwappedByteBuf. On little-endian platforms, this causes a double byte reversal:

      • First, we read the buffer in LE, reversing bytes to BE
      • Then, the SwappedByteBuf reverses them again to simulate LE

      This results in unnecessary overhead.

      In addition, Netty’s javadoc documentation on order() method advises:

      Use the Little Endian accessors (e.g., getShortLE, getIntLE) instead of creating a buffer with swapped endianness via order().

      We should:

      • Remove the call to order(LITTLE_ENDIAN)
      • Internally track endianness via a boolean (e.g., isLittleEndian)

      Based on this flag, use the appropriate Netty accessor methods:

      • getLongLE, getIntLE, etc. for LE
      • getLong, getInt, etc. for BE

      This avoids the creation of an intermediate SwappedByteBuf and prevents redundant byte reversal logic.

            Assignee:
            Unassigned
            Reporter:
            Slav Babanin
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: