[CSHARP-2456] Use less memory without scope capturing Created: 14/Dec/18 Updated: 06/Jun/23 |
|
| Status: | Backlog |
| Project: | C# Driver |
| Component/s: | Json, Performance |
| Affects Version/s: | 2.7.2 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Nikolay Mitikov | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Any, its about C# driver doing same, but faster |
||
| Issue Links: |
|
||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||
| Description |
|
JsonWriter.EscapedString implementation uses anonymous function that touches instance private method - forces compiler to capture scope with 'this' for each =\ We can switch from .All LINQ to hand written method to avoid object allocation each time method called (super-often). Thanks. |
| Comments |
| Comment by Nikolay Mitikov [ 18/Dec/18 ] |
|
Hi @ian.whalen, yep, we can! I see few options for data collection during any Json serialization/deserialization - measure either memory traffic (volume of allocated objects), or check memory snapshots 1) Launch PerfView session with defaults and inspect 'GC Heap Alloc Ignore Free' memory views - how many objects were allocated 2) Collect memory snapshot at random time and perform '!dumpheap -stat' to locate objects living in heap Alternatively we can mimic both codes in Benchmark.NET tests with Memory Diagnoser on.
I my case it was around 1M objects created in the heap -> ~24 MB of useless pressure captured at a moment in time. The perf. win is small, but still better than no win. |
| Comment by Ian Whalen (Inactive) [ 17/Dec/18 ] |
|
nik thanks for opening the ticket here. Do you have any measurements you can add to highlight the benefit we might see here? |
| Comment by Ian Whalen (Inactive) [ 14/Dec/18 ] |