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

.NET 8 Update(6): CollectionsMarshal for ListFormatter #1732

Merged
merged 4 commits into from
Jan 14, 2024

Conversation

pCYSl5EDgo
Copy link
Contributor

List<T> for loop is slower than Span<T> for loop.
CollectionsMarshal.AsSpan converts List<T> to Span<T>
CollectionsMarshal.SetCount can be used for deserialize.

@pCYSl5EDgo pCYSl5EDgo mentioned this pull request Jan 11, 2024
14 tasks
@pCYSl5EDgo pCYSl5EDgo changed the title .Net 8 Update: CollectionsMarshal for ListFormatter .Net 8 Update(6): CollectionsMarshal for ListFormatter Jan 11, 2024
Copy link
Collaborator

@AArnott AArnott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. Did you happen to measure perf impact of this change?

@pCYSl5EDgo
Copy link
Contributor Author

pCYSl5EDgo commented Jan 13, 2024

The below benchmarks were done without Dynamic PGO.
With Dynamic PGO, there was no difference between new formatter and old formatter.

List<byte>


BenchmarkDotNet v0.13.12, Windows 11 (10.0.22621.3007/22H2/2022Update/SunValley2)
Intel Core i7-8750H CPU 2.20GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
.NET SDK 8.0.101
  [Host]     : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2


Method Size Mean Error StdDev
SerializeNew 1 73.66 ns 1.510 ns 1.615 ns
SerializeOld 1 76.72 ns 1.452 ns 1.728 ns
DeserializeNew 1 89.63 ns 1.852 ns 2.535 ns
DeserializeOld 1 90.21 ns 1.846 ns 4.665 ns
SerializeNew 64 257.25 ns 5.140 ns 5.279 ns
SerializeOld 64 258.83 ns 4.092 ns 5.025 ns
DeserializeNew 64 441.35 ns 8.431 ns 7.474 ns
DeserializeOld 64 481.55 ns 7.090 ns 6.286 ns
SerializeNew 1024 3,420.87 ns 66.383 ns 71.029 ns
SerializeOld 1024 3,415.81 ns 13.653 ns 11.401 ns
DeserializeNew 1024 9,625.97 ns 191.207 ns 255.256 ns
DeserializeOld 1024 10,175.56 ns 203.576 ns 217.824 ns
SerializeNew 16777216 122,029,780.00 ns 1,344,153.681 ns 1,257,322.187 ns
SerializeOld 16777216 131,873,157.69 ns 2,493,291.890 ns 3,412,846.081 ns
DeserializeNew 16777216 160,013,514.81 ns 3,050,381.441 ns 4,276,208.758 ns
DeserializeOld 16777216 167,149,218.84 ns 3,336,039.530 ns 4,219,021.850 ns

List<Matrix4x4>


BenchmarkDotNet v0.13.12, Windows 11 (10.0.22621.3007/22H2/2022Update/SunValley2)
Intel Core i7-8750H CPU 2.20GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
.NET SDK 8.0.101
  [Host]     : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2


Method Size Mean Error StdDev
SerializeNew 1 142.7 ns 2.87 ns 3.31 ns
SerializeOld 1 141.5 ns 2.56 ns 4.20 ns
DeserializeNew 1 220.5 ns 4.03 ns 5.51 ns
DeserializeOld 1 218.0 ns 3.89 ns 3.64 ns
SerializeNew 64 4,730.6 ns 68.85 ns 57.50 ns
SerializeOld 64 4,931.7 ns 98.49 ns 209.89 ns
DeserializeNew 64 8,431.1 ns 163.43 ns 194.56 ns
DeserializeOld 64 8,365.5 ns 146.44 ns 129.81 ns
SerializeNew 1024 149,412.6 ns 2,915.70 ns 4,364.08 ns
SerializeOld 1024 142,725.7 ns 2,752.63 ns 3,276.81 ns
DeserializeNew 1024 142,506.2 ns 2,848.95 ns 5,064.01 ns
DeserializeOld 1024 145,993.7 ns 2,861.05 ns 3,916.24 ns
SerializeNew 16777216 1,588,265,229.5 ns 38,374,748.24 ns 105,695,201.32 ns
SerializeOld 16777216 1,502,806,044.9 ns 28,744,116.00 ns 69,420,270.85 ns
DeserializeNew 16777216 2,413,118,764.5 ns 46,612,636.71 ns 71,182,419.37 ns
DeserializeOld 16777216 2,586,872,945.1 ns 51,537,327.26 ns 126,421,942.00 ns

@pCYSl5EDgo
Copy link
Contributor Author

pCYSl5EDgo commented Jan 13, 2024

For smaller value types, Serialize of this PR is more performant than original one.
But for bigger value types Serialize of this PR is slower than original one.

Deserialize of this PR is in most cases better than original.

Considering the above facts, let's revert the change for Serialize.

@AArnott AArnott added this to the v2.6 milestone Jan 14, 2024
@AArnott AArnott merged commit bed1f44 into MessagePack-CSharp:develop Jan 14, 2024
4 of 5 checks passed
@pCYSl5EDgo pCYSl5EDgo deleted the net8-cm branch January 14, 2024 02:38
@pCYSl5EDgo pCYSl5EDgo changed the title .Net 8 Update(6): CollectionsMarshal for ListFormatter .NET 8 Update(6): CollectionsMarshal for ListFormatter Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants