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

Performance: Reduce byte buffer allocations while writing to server

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.8.1, 2.9.0
    • Fix Version/s: 2.12.0
    • Component/s: Performance, Serialization
    • Labels:
      None

      Description

      Similar to https://jira.mongodb.org/browse/CSHARP-2692, calling Utf8Encoding.GetBytes without specifying a byte buffer should be avoided at all costs for best performance.

      The current implementation of ByteBufferStream does already have a concept (using the "_tempUtf8" buffer) where it ends up calling the fast GetBytes() overload that doesn't allocate its own buffer for strings up to a length that fits into a byte[128] buffer. The 128 elements are a hard limit, though, so for bigger strings, there is a performance penalty.

      I suggest changing this by auto-growing the byte[128] buffer to handle bigger strings, too. This is trading a little bit of memory for performance.

        Attachments

          Activity

            People

            Assignee:
            boris.dogadov Boris Dogadov
            Reporter:
            dnickless dnickless
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: