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

Optimize Array Index Name Encoding in BsonBinaryWriter

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 5.5.0
    • Affects Version/s: None
    • Component/s: None
    • 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

      In BsonBinaryWriter, array element field names are currently generated using Integer.toString(index) on each write. This creates new string instances repeatedly during BSON array serialization, which can be inefficient for large arrays and adds unnecessary GC pressure.

      To improve performance, we should introduce a cache of precomputed string representations for commonly used array indexes (e.g., 0 to 255). These cached values can be reused when writing array element names, avoiding repetitive allocations.

      Rationale:

      • Reduces memory allocations and GC overhead when writing large arrays

      This change will benefit workloads involving large BSON arrays.

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

              Created:
              Updated:
              Resolved: