[CSHARP-2504] Reduce memory consumption because of lambda closures in BsonWriter.WriteName Created: 06/Feb/19 Updated: 28/Oct/23 Resolved: 07/Jan/21 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Performance, Serialization |
| Affects Version/s: | 2.7.3 |
| Fix Version/s: | 2.12.0 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Daniel Hegener | Assignee: | Boris Dogadov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
The profiler output of a session that involved serialization of more than 2 million complex documents shows the following result - 36GB of memory allocated only by the BsonWriter.WriteName method:
The culprit for that appears to be the lambda expression here: https://github.com/mongodb/mongo-csharp-driver/blob/dc2dbb5ff06fdea80b44a8c2295e542f166ccb16/src/MongoDB.Bson/IO/BsonWriter.cs#L279
It would certainly be beneficial to move to an alternative design that does not result in closures. |
| Comments |
| Comment by Boris Dogadov [ 07/Jan/21 ] |
|
Thanks onyxmaster and dnickless for finding and submitting PRs for this issue. |
| Comment by Githook User [ 07/Jan/21 ] |
|
Author: {'name': 'Boris', 'email': 'boris.dogadov@mongodb.com', 'username': 'BorisDog'}Message: |
| Comment by Aristarkh Zagorodnikov [ 07/Dec/20 ] |
|
I wonder why would you close an older issue, |
| Comment by Daniel Hegener [ 20/Feb/19 ] |
| Comment by Daniel Hegener [ 06/Feb/19 ] |
|
Here is another screenshot of the same profiling session showing another area where the current pattern allocates memory:
|