-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 2.7.2
-
Component/s: BSON, Performance
-
None
-
Environment:All
-
Fully Compatible
-
Not Needed
-
MongoDB.Bson/IO/JsonWriter.cs
Regarding the following function:
private string EscapedString(string value)
and the following line of code:
var sb = new StringBuilder(value.Length);
This StringBuilder object is being created because the string named "value" needs escaping. It is unknown at this point exactly how many characters need escaping, but AT MINIMUM there is one. This means the new escaped string length will be larger than original string length by at least one character, and the StringBuilder constructor capacity parameter should reflect this logic. Without this change, the StringBuilder object is GUARANTEED to allocate and chain together a new StringBuilder object under the hood as it increases it's capacity to handle the larger escaped string.
- related to
-
CSHARP-2456 Use less memory without scope capturing
- Closed