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

ByteBufferedBsonOutput Numeric Optimizations

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Performance
    • None
    • Java Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      The current implementation of writing numeric values to buffers involves manual byte manipulation, which can introduce overhead. This task proposes refactoring the serialization logic to leverage ByteBuffer's methods such as putInt, putLong, and putDouble. These methods are optimized for bulk operations and can improve the performance of data serialization.

      Those methods are often intrinsified, meaning the JVM might replace its bytecode with a single, efficient machine instruction, eliminating the overhead of a native method call. For example, on x86 architectures, the Integer.reverseBytes(int i) method can be intrinsified to use the BSWAP assembly instruction, which efficiently reverses the byte order of a 32-bit integer. Similarly, on ARM architectures, it can utilize the REV instruction for the same purpose. 

      Acceptance Criteria:

      • Refactor existing code to replace manual byte writes with ByteBuffer's putInt, putLong, and putDouble methods where applicable.​
      • Ensure all unit and integration tests pass, confirming that the changes do not introduce regressions.​
      • Consider adding additional tests to ensure thorough coverage. 
      • Benchmark the performance before and after the changes to quantify improvements.

            Assignee:
            slav.babanin@mongodb.com Slav Babanin
            Reporter:
            slav.babanin@mongodb.com Slav Babanin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              None
              None
              None
              None