Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2505

Reduce array allocations in BsonStreamAdapter

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.7.3
    • Component/s: Performance, Serialization
    • None
    • 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?

      BsonStreamAdapter already uses some kind of an array reuse concept using the _tempUtf8 variable. This approach could, however, be significantly improved by dropping this helper variable and instead switching to System.Buffers.ArrayPool<byte>. The reason being that e.g. for the UTF8 conversions in WriteString() and WriteCString, the buffers are only needed for a very short time and can immediately (at the end of the very same method) be returned back to the pool once the buffer has been written into the output stream.

            Assignee:
            Unassigned Unassigned
            Reporter:
            daniel.hegener@gmx.net Daniel Hegener
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: