-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 2.8.1, 2.9.0
-
Component/s: Performance, Serialization
-
None
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.