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

add type include / exclude for polymorphic serializers #226

Closed
Aaronontheweb opened this issue Jun 7, 2021 · 4 comments
Closed

add type include / exclude for polymorphic serializers #226

Aaronontheweb opened this issue Jun 7, 2021 · 4 comments
Assignees
Milestone

Comments

@Aaronontheweb
Copy link
Member

See akkadotnet/akka.net#5026 for full proposal. Covers both Hyperion and Newtonsoft.Json.

@Aaronontheweb
Copy link
Member Author

Recommend implementing this on Hyperion first. Shouldn't have a performance impact if not explicitly enabled (opt-in.)

@Aaronontheweb
Copy link
Member Author

Resolved via #242

@Aaronontheweb
Copy link
Member Author

Performance numbers associated with this change, as collected by @Arkatufus

Summary

.NET Framework 4.7.1

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19041.1165 (2004/May2020Update/20H1)
AMD Ryzen 9 3900X, 1 CPU, 24 logical and 12 physical cores
  [Host]     : .NET Framework 4.8 (4.8.4400.0), X64 RyuJIT
  DefaultJob : .NET Framework 4.8 (4.8.4400.0), X64 RyuJIT

Before

Method Mean Error StdDev Min Max Op/s Gen 0 Allocated
Cyclic_References 926.4 ns 5.47 ns 5.12 ns 916.2 ns 935.8 ns 1,079,393.1 0.1888 1 KB
Virtual_Classes 735.6 ns 2.21 ns 2.07 ns 732.5 ns 739.4 ns 1,359,456.8 0.1850 1 KB
Large_Sealed_Classes 3,187.7 ns 5.71 ns 5.34 ns 3,179.2 ns 3,197.7 ns 313,706.3 0.4311 3 KB
Generic_Classes 1,867.1 ns 7.53 ns 7.04 ns 1,855.8 ns 1,877.4 ns 535,592.3 0.2174 1 KB

After

Method Mean Error StdDev Min Max Op/s Gen 0 Allocated
Cyclic_References 927.0 ns 2.95 ns 2.76 ns 922.7 ns 931.7 ns 1,078,763.3 0.1888 1 KB
Virtual_Classes 740.7 ns 2.32 ns 2.17 ns 737.2 ns 745.3 ns 1,350,157.3 0.1850 1 KB
Large_Sealed_Classes 3,314.0 ns 12.06 ns 10.69 ns 3,291.9 ns 3,328.9 ns 301,752.4 0.4349 3 KB
Generic_Classes 1,857.0 ns 5.82 ns 5.44 ns 1,843.5 ns 1,863.1 ns 538,495.5 0.2174 1 KB

.NET 5.0

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19041.1165 (2004/May2020Update/20H1)
AMD Ryzen 9 3900X, 1 CPU, 24 logical and 12 physical cores
.NET SDK=5.0.201
  [Host]     : .NET 5.0.4 (5.0.421.11614), X64 RyuJIT
  DefaultJob : .NET 5.0.4 (5.0.421.11614), X64 RyuJIT

Before

Method Mean Error StdDev Min Max Op/s Gen 0 Allocated
Cyclic_References 1,017.7 ns 7.71 ns 6.83 ns 1,008.0 ns 1,030.9 ns 982,629.8 0.1392 1 KB
Virtual_Classes 769.7 ns 3.96 ns 3.31 ns 763.7 ns 775.5 ns 1,299,132.3 0.1364 1 KB
Large_Sealed_Classes 2,961.5 ns 11.13 ns 10.42 ns 2,947.2 ns 2,981.6 ns 337,666.1 0.3166 3 KB
Generic_Classes 1,662.5 ns 3.92 ns 3.67 ns 1,653.0 ns 1,668.7 ns 601,499.3 0.1698 1 KB

After

Method Mean Error StdDev Min Max Op/s Gen 0 Allocated
Cyclic_References 1,003.1 ns 3.28 ns 2.90 ns 996.9 ns 1,008.0 ns 996,898.0 0.1392 1 KB
Virtual_Classes 774.3 ns 4.82 ns 4.51 ns 768.1 ns 783.2 ns 1,291,423.9 0.1364 1 KB
Large_Sealed_Classes 3,028.5 ns 14.32 ns 13.39 ns 3,006.6 ns 3,049.4 ns 330,200.7 0.3166 3 KB
Generic_Classes 1,648.9 ns 6.56 ns 6.14 ns 1,637.9 ns 1,655.3 ns 606,480.9 0.1698 1 KB

.NET Core 3.1

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19041.1165 (2004/May2020Update/20H1)
AMD Ryzen 9 3900X, 1 CPU, 24 logical and 12 physical cores
.NET SDK=5.0.201
  [Host]     : .NET Core 3.1.13 (CoreCLR 4.700.21.11102, CoreFX 4.700.21.11602), X64 RyuJIT
  DefaultJob : .NET Core 3.1.13 (CoreCLR 4.700.21.11102, CoreFX 4.700.21.11602), X64 RyuJIT

Before

Method Mean Error StdDev Min Max Op/s Gen 0 Allocated
Cyclic_References 1,031.0 ns 6.01 ns 5.62 ns 1,024.3 ns 1,043.9 ns 969,888.8 0.1373 1 KB
Virtual_Classes 842.2 ns 3.96 ns 3.51 ns 834.2 ns 847.9 ns 1,187,322.9 0.1354 1 KB
Large_Sealed_Classes 2,973.1 ns 10.71 ns 9.50 ns 2,961.2 ns 2,996.1 ns 336,344.7 0.3166 3 KB
Generic_Classes 1,725.5 ns 5.60 ns 4.96 ns 1,715.1 ns 1,731.4 ns 579,553.1 0.1678 1 KB

After

Method Mean Error StdDev Min Max Op/s Gen 0 Allocated
Cyclic_References 1,034.1 ns 5.32 ns 4.98 ns 1,027.6 ns 1,045.0 ns 967,024.1 0.1373 1 KB
Virtual_Classes 816.1 ns 3.01 ns 2.67 ns 809.7 ns 820.3 ns 1,225,334.8 0.1354 1 KB
Large_Sealed_Classes 3,034.7 ns 11.81 ns 11.05 ns 3,016.4 ns 3,055.7 ns 329,520.8 0.3166 3 KB
Generic_Classes 1,719.3 ns 7.57 ns 6.71 ns 1,711.2 ns 1,730.1 ns 581,631.5 0.1678 1 KB

@Aaronontheweb
Copy link
Member Author

And disallow unsafe types is enabled by default:

: this(versionTolerance, preserveObjectReferences, surrogates, serializerFactories, knownTypes, ignoreISerializable, null, true)

So this benchmark definitely included them. Looks to me like the overhead from introducing the unsafe type filtering is pretty minimal due to caching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants