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

ByteBufferedBsonOutput Numeric Optimizations

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

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • 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
            Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: