Fix some low-hanging fruit boxing in JsonSerializer#40867
Fix some low-hanging fruit boxing in JsonSerializer#40867stephentoub merged 1 commit intodotnet:masterfrom
Conversation
It's boxing lots of dictionary enumerators and KeyValuePairs. Stop doing that.
src/System.Text.Json/src/System/Text/Json/Serialization/WriteStackFrame.cs
Show resolved
Hide resolved
|
Did a/could a analyzer help find these? |
An analyzer to detect boxing sounds wonderful :). |
src/System.Text.Json/src/System/Text/Json/Serialization/WriteStackFrame.cs
Show resolved
Hide resolved
No. I was testing out the memory profiler and these jumped out at me (any time you see structs show up in the allocation list, it's a red flag).
It could, but such analyzers are super, super noisy. There are lots of things in .NET that can result in hidden allocations, whether it be boxing, lambdas capturing locals, etc., and there are many legitimate uses for those.
Such analyzers exist, e.g. https://github.com/Microsoft/RoslynClrHeapAllocationAnalyzer. But as noted above, they're much more useful in my experience as an exploratory tool, where you turn it on every once in a while locally and look for things you weren't expecting; as part of a build, they result in so much noise you quickly want to rip it out. |
) It's boxing lots of dictionary enumerators and KeyValuePairs. Stop doing that. Commit migrated from dotnet/corefx@447f76f
It's boxing lots of dictionary enumerators and KeyValuePairs. Stop doing that.
cc: @steveharter, @ahsonkhan, @layomia
Before:

After:

Repro: