Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement thread-local caching for Utf8JsonWriter in JsonSerializer. #73338

Merged
merged 4 commits into from
Aug 5, 2022

Conversation

eiriktsarpalis
Copy link
Member

Following recommendation in #69889. Records nice improvements in the allocation profile when serializing small-ish values.

cc @davidfowl

WriteJson<int>

Method Job Toolchain Mean Error StdDev Median Min Max Ratio MannWhitney(3%) RatioSD Gen 0 Allocated Alloc Ratio
SerializeToString Job-PLUXQS main 120.17 ns 2.334 ns 2.184 ns 119.68 ns 116.27 ns 125.73 ns 1.00 Base 0.00 0.0182 184 B 1.00
SerializeToString Job-YSJKRU PR 123.69 ns 2.042 ns 1.705 ns 123.15 ns 120.87 ns 126.57 ns 1.03 Same 0.02 0.0030 32 B 0.17
SerializeToUtf8Bytes Job-PLUXQS main 105.70 ns 2.059 ns 1.826 ns 106.01 ns 102.20 ns 109.37 ns 1.00 Base 0.00 0.0181 184 B 1.00
SerializeToUtf8Bytes Job-YSJKRU PR 99.58 ns 2.058 ns 2.202 ns 98.58 ns 97.10 ns 103.77 ns 0.94 Faster 0.03 0.0028 32 B 0.17

WriteJson<LoginViewModel>

Method Job Branch Mean Error StdDev Median Min Max Ratio MannWhitney(3%) RatioSD Gen 0 Allocated Alloc Ratio
SerializeToString Job-PLUXQS main 315.8 ns 10.84 ns 12.49 ns 314.0 ns 294.3 ns 338.3 ns 1.00 Base 0.00 0.0338 344 B 1.00
SerializeToString Job-YSJKRU PR 302.3 ns 4.02 ns 3.14 ns 302.8 ns 293.6 ns 306.6 ns 0.98 Same 0.03 0.0180 192 B 0.56
SerializeToUtf8Bytes Job-PLUXQS main 278.0 ns 5.09 ns 4.52 ns 279.4 ns 270.3 ns 284.2 ns 1.00 Base 0.00 0.0252 264 B 1.00
SerializeToUtf8Bytes Job-YSJKRU PR 282.4 ns 5.73 ns 6.37 ns 281.5 ns 273.0 ns 296.5 ns 1.02 Same 0.03 0.0110 112 B 0.42

WriteJson<Dictionary<string,string>> (Count == 100)

Method Job Toolchain Mean Error StdDev Median Min Max Ratio MannWhitney(3%) RatioSD Gen 0 Gen 1 Allocated Alloc Ratio
SerializeToString Job-PLUXQS main 9.233 μs 0.1798 μs 0.1594 μs 9.188 μs 8.996 μs 9.466 μs 1.00 Base 0.00 1.1623 0.0375 12008 B 1.00
SerializeToString Job-YSJKRU PR 9.258 μs 0.2519 μs 0.2900 μs 9.243 μs 8.797 μs 9.957 μs 1.00 Same 0.04 1.1621 0.0363 11856 B 0.99
SerializeToUtf8Bytes Job-PLUXQS main 8.349 μs 0.0805 μs 0.0673 μs 8.352 μs 8.235 μs 8.448 μs 1.00 Base 0.00 0.5759 - 6096 B 1.00
SerializeToUtf8Bytes Job-YSJKRU PR 8.817 μs 0.4493 μs 0.5174 μs 8.516 μs 8.335 μs 10.016 μs 1.08 Same 0.07 0.5688 - 5944 B 0.98

Fix #69889.

@eiriktsarpalis eiriktsarpalis added this to the 7.0.0 milestone Aug 3, 2022
@eiriktsarpalis eiriktsarpalis self-assigned this Aug 3, 2022
@ghost
Copy link

ghost commented Aug 3, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

Following recommendation in #69889. Records nice improvements in the allocation profile when serializing small-ish values.

cc @davidfowl

WriteJson<int>

Method Job Toolchain Mean Error StdDev Median Min Max Ratio MannWhitney(3%) RatioSD Gen 0 Allocated Alloc Ratio
SerializeToString Job-PLUXQS main 120.17 ns 2.334 ns 2.184 ns 119.68 ns 116.27 ns 125.73 ns 1.00 Base 0.00 0.0182 184 B 1.00
SerializeToString Job-YSJKRU PR 123.69 ns 2.042 ns 1.705 ns 123.15 ns 120.87 ns 126.57 ns 1.03 Same 0.02 0.0030 32 B 0.17
SerializeToUtf8Bytes Job-PLUXQS main 105.70 ns 2.059 ns 1.826 ns 106.01 ns 102.20 ns 109.37 ns 1.00 Base 0.00 0.0181 184 B 1.00
SerializeToUtf8Bytes Job-YSJKRU PR 99.58 ns 2.058 ns 2.202 ns 98.58 ns 97.10 ns 103.77 ns 0.94 Faster 0.03 0.0028 32 B 0.17

WriteJson<LoginViewModel>

Method Job Branch Mean Error StdDev Median Min Max Ratio MannWhitney(3%) RatioSD Gen 0 Allocated Alloc Ratio
SerializeToString Job-PLUXQS main 315.8 ns 10.84 ns 12.49 ns 314.0 ns 294.3 ns 338.3 ns 1.00 Base 0.00 0.0338 344 B 1.00
SerializeToString Job-YSJKRU PR 302.3 ns 4.02 ns 3.14 ns 302.8 ns 293.6 ns 306.6 ns 0.98 Same 0.03 0.0180 192 B 0.56
SerializeToUtf8Bytes Job-PLUXQS main 278.0 ns 5.09 ns 4.52 ns 279.4 ns 270.3 ns 284.2 ns 1.00 Base 0.00 0.0252 264 B 1.00
SerializeToUtf8Bytes Job-YSJKRU PR 282.4 ns 5.73 ns 6.37 ns 281.5 ns 273.0 ns 296.5 ns 1.02 Same 0.03 0.0110 112 B 0.42

WriteJson<Dictionary<string,string>> (Count == 100)

Method Job Toolchain Mean Error StdDev Median Min Max Ratio MannWhitney(3%) RatioSD Gen 0 Gen 1 Allocated Alloc Ratio
SerializeToString Job-PLUXQS main 9.233 μs 0.1798 μs 0.1594 μs 9.188 μs 8.996 μs 9.466 μs 1.00 Base 0.00 1.1623 0.0375 12008 B 1.00
SerializeToString Job-YSJKRU PR 9.258 μs 0.2519 μs 0.2900 μs 9.243 μs 8.797 μs 9.957 μs 1.00 Same 0.04 1.1621 0.0363 11856 B 0.99
SerializeToUtf8Bytes Job-PLUXQS main 8.349 μs 0.0805 μs 0.0673 μs 8.352 μs 8.235 μs 8.448 μs 1.00 Base 0.00 0.5759 - 6096 B 1.00
SerializeToUtf8Bytes Job-YSJKRU PR 8.817 μs 0.4493 μs 0.5174 μs 8.516 μs 8.335 μs 10.016 μs 1.08 Same 0.07 0.5688 - 5944 B 0.98

Fix #69889.

Author: eiriktsarpalis
Assignees: eiriktsarpalis
Labels:

area-System.Text.Json, tenet-performance

Milestone: 7.0.0

@eiriktsarpalis eiriktsarpalis merged commit 608e516 into dotnet:main Aug 5, 2022
@eiriktsarpalis eiriktsarpalis deleted the utf8jsonwriter-cache branch August 5, 2022 10:28
@ghost ghost locked as resolved and limited conversation to collaborators Sep 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider caching Utf8JsonWriter and PooledByteBufferWriter on a thread static in JsonSerializer.Serialize
2 participants