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

TypelessContractlessStandardResolver 10 times slower than StandardResolver #102

Closed
alexvaluyskiy opened this Issue Aug 9, 2017 · 6 comments

Comments

Projects
None yet
2 participants
@alexvaluyskiy

alexvaluyskiy commented Aug 9, 2017

I've created a benchmark to compare TypelessContractlessStandardResolver and StandardResolver and have found that it could be up to 10 time slower

Benchmark code: https://gist.github.com/alexvaluyskiy/4f65933ddb6f5886b023bcc90ae9bc98

BenchmarkDotNet=v0.10.9, OS=Windows 10 Redstone 2 (10.0.15063)
Processor=Intel Core i5-6400 CPU 2.70GHz (Skylake), ProcessorCount=4
Frequency=2648437 Hz, Resolution=377.5812 ns, Timer=TSC
  [Host]      : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2102.0
  NET 4.7     : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2102.0
  NETCore 1.1 : .NET Core 1.1.2 (Framework 4.6.25211.01), 64bit RyuJIT
  NETCore 2.0 : .NET Core 2.0.0-preview3-25518-01 (Framework 4.6.00001.0), 64bit RyuJIT

Jit=RyuJit  Platform=X64  Server=True  

Serialize

Method Job Runtime Toolchain Mean Error StdDev Scaled ScaledSD Gen 0 Allocated
MessagePackSerializer_Serialize_StandardResolver NET 4.7 Clr Default 202.5 ns 0.6068 ns 0.5676 ns 1.00 0.00 0.0010 40 B
MessagePackSerializer_Serialize_ContractlessStandardResolver NET 4.7 Clr Default 320.2 ns 0.8527 ns 0.7120 ns 1.58 0.01 0.0015 64 B
MessagePackSerializer_Serialize_TypelessContractlessStandardResolver_primitive NET 4.7 Clr Default 364.7 ns 1.7355 ns 1.6234 ns 1.80 0.01 0.0010 48 B
MessagePackSerializer_Serialize_TypelessContractlessStandardResolver_complex NET 4.7 Clr Default 3,759.5 ns 38.7135 ns 36.2126 ns 18.56 0.18 0.0142 656 B
MessagePackSerializer_Serialize_StandardResolver NETCore 1.1 Core CoreCsProj 194.1 ns 0.7988 ns 0.7472 ns 1.00 0.00 0.0010 40 B
MessagePackSerializer_Serialize_ContractlessStandardResolver NETCore 1.1 Core CoreCsProj 250.9 ns 2.1929 ns 2.0512 ns 1.29 0.01 0.0015 64 B
MessagePackSerializer_Serialize_TypelessContractlessStandardResolver_primitive NETCore 1.1 Core CoreCsProj 346.9 ns 3.1161 ns 2.9148 ns 1.79 0.02 0.0010 48 B
MessagePackSerializer_Serialize_TypelessContractlessStandardResolver_complex NETCore 1.1 Core CoreCsProj 3,398.1 ns 43.0616 ns 40.2799 ns 17.50 0.21 0.0127 560 B
MessagePackSerializer_Serialize_StandardResolver NETCore 2.0 Core CoreCsProj 203.8 ns 0.7997 ns 0.7089 ns 1.00 0.00 0.0010 40 B
MessagePackSerializer_Serialize_ContractlessStandardResolver NETCore 2.0 Core CoreCsProj 259.3 ns 0.7807 ns 0.6095 ns 1.27 0.01 0.0014 64 B
MessagePackSerializer_Serialize_TypelessContractlessStandardResolver_primitive NETCore 2.0 Core CoreCsProj 337.8 ns 0.9775 ns 0.9143 ns 1.66 0.01 0.0010 48 B
MessagePackSerializer_Serialize_TypelessContractlessStandardResolver_complex NETCore 2.0 Core CoreCsProj 2,947.5 ns 21.1082 ns 19.7446 ns 14.46 0.11 0.0137 560 B

Deserialize

Method Job Runtime Toolchain Mean Error StdDev Scaled ScaledSD Gen 0 Allocated
MessagePackSerializer_Deserialize_StandardResolver NET 4.7 Clr Default 227.3 ns 1.4442 ns 1.2803 ns 1.00 0.00 0.0042 144 B
MessagePackSerializer_Deserialize_ContractlessStandardResolver NET 4.7 Clr Default 439.1 ns 4.2986 ns 4.0209 ns 1.93 0.02 0.0039 144 B
MessagePackSerializer_Deserialize_TypelessContractlessStandardResolver NET 4.7 Clr Default 247.9 ns 1.1392 ns 0.9513 ns 1.09 0.01 0.0026 96 B
MessagePackSerializer_Deserialize_TypelessContractlessStandardResolverComplexBytes NET 4.7 Clr Default 4,051.5 ns 80.7790 ns 86.4326 ns 17.82 0.38 0.0031 304 B
MessagePackSerializer_Deserialize_StandardResolver NETCore 1.1 Core CoreCsProj 215.9 ns 1.9250 ns 1.8007 ns 1.00 0.00 0.0044 144 B
MessagePackSerializer_Deserialize_ContractlessStandardResolver NETCore 1.1 Core CoreCsProj 430.7 ns 3.4806 ns 3.2558 ns 2.00 0.02 0.0038 144 B
MessagePackSerializer_Deserialize_TypelessContractlessStandardResolver NETCore 1.1 Core CoreCsProj 232.9 ns 0.5914 ns 0.5532 ns 1.08 0.01 0.0026 96 B
MessagePackSerializer_Deserialize_TypelessContractlessStandardResolverComplexBytes NETCore 1.1 Core CoreCsProj 4,024.9 ns 22.9254 ns 20.3227 ns 18.65 0.18 0.0031 304 B
MessagePackSerializer_Deserialize_StandardResolver NETCore 2.0 Core CoreCsProj 221.1 ns 0.9301 ns 0.8701 ns 1.00 0.00 0.0043 144 B
MessagePackSerializer_Deserialize_ContractlessStandardResolver NETCore 2.0 Core CoreCsProj 385.8 ns 1.2942 ns 1.1473 ns 1.74 0.01 0.0041 144 B
MessagePackSerializer_Deserialize_TypelessContractlessStandardResolver NETCore 2.0 Core CoreCsProj 218.8 ns 0.7750 ns 0.7249 ns 0.99 0.00 0.0026 96 B
MessagePackSerializer_Deserialize_TypelessContractlessStandardResolverComplexBytes NETCore 2.0 Core CoreCsProj 3,983.1 ns 60.9857 ns 57.0460 ns 18.01 0.26 0.0036 304 B
@neuecc

This comment has been minimized.

Show comment
Hide comment
@neuecc

neuecc Aug 10, 2017

Owner

Typeless is not very optimized.
However, it is a bit terrible.

I should improve it, thank you.

Owner

neuecc commented Aug 10, 2017

Typeless is not very optimized.
However, it is a bit terrible.

I should improve it, thank you.

@neuecc

This comment has been minimized.

Show comment
Hide comment
@neuecc

neuecc Aug 18, 2017

Owner

improved deserialize speed.

image

Owner

neuecc commented Aug 18, 2017

improved deserialize speed.

image

@neuecc

This comment has been minimized.

Show comment
Hide comment
@neuecc

neuecc Aug 18, 2017

Owner

improved serialize speed(not yet done for some types)

image

Owner

neuecc commented Aug 18, 2017

improved serialize speed(not yet done for some types)

image

@neuecc

This comment has been minimized.

Show comment
Hide comment
@neuecc

neuecc Aug 19, 2017

Owner

Final Result

Serialize
2692ns -> 318ns

Deserialize
3043ns -> 446ns

It is approximately 8 times performance improvement.

Serialize

Method Mean Error Gen 0 Allocated
Old_MessagePackSerializer_Serialize_StandardResolver 169.2 ns NA 0.0093 40 B
Old_MessagePackSerializer_Serialize_ContractlessStandardResolver 234.9 ns NA 0.0148 64 B
Old_MessagePackSerializer_Serialize_TypelessContractlessStandardResolver_primitive 266.9 ns NA 0.0110 48 B
Old_MessagePackSerializer_Serialize_TypelessContractlessStandardResolver_complex 2,692.9 ns NA 0.1564 656 B
MessagePackSerializer_Serialize_StandardResolver 158.0 ns NA 0.0093 40 B
MessagePackSerializer_Serialize_ContractlessStandardResolver 245.2 ns NA 0.0150 64 B
MessagePackSerializer_Serialize_TypelessContractlessStandardResolver_primitive 210.6 ns NA 0.0188 80 B
MessagePackSerializer_Serialize_TypelessContractlessStandardResolver_complex 318.5 ns NA 0.0319 136 B

Deserialize

Method Mean Error Gen 0 Allocated
Old_MessagePackSerializer_Deserialize_StandardResolver 171.8 ns NA 0.0341 144 B
Old_MessagePackSerializer_Deserialize_ContractlessStandardResolver 308.0 ns NA 0.0339 144 B
Old_MessagePackSerializer_Deserialize_TypelessContractlessStandardResolver 169.8 ns NA 0.0226 96 B
Old_MessagePackSerializer_Deserialize_TypelessContractlessStandardResolverComplexBytes 3,043.2 ns NA 0.0687 296 B
MessagePackSerializer_Deserialize_StandardResolver 165.7 ns NA 0.0341 144 B
MessagePackSerializer_Deserialize_ContractlessStandardResolver 309.5 ns NA 0.0339 144 B
MessagePackSerializer_Deserialize_TypelessContractlessStandardResolver 253.2 ns NA 0.0224 96 B
MessagePackSerializer_Deserialize_TypelessContractlessStandardResolverComplexBytes 446.4 ns NA 0.0339 144 B
Owner

neuecc commented Aug 19, 2017

Final Result

Serialize
2692ns -> 318ns

Deserialize
3043ns -> 446ns

It is approximately 8 times performance improvement.

Serialize

Method Mean Error Gen 0 Allocated
Old_MessagePackSerializer_Serialize_StandardResolver 169.2 ns NA 0.0093 40 B
Old_MessagePackSerializer_Serialize_ContractlessStandardResolver 234.9 ns NA 0.0148 64 B
Old_MessagePackSerializer_Serialize_TypelessContractlessStandardResolver_primitive 266.9 ns NA 0.0110 48 B
Old_MessagePackSerializer_Serialize_TypelessContractlessStandardResolver_complex 2,692.9 ns NA 0.1564 656 B
MessagePackSerializer_Serialize_StandardResolver 158.0 ns NA 0.0093 40 B
MessagePackSerializer_Serialize_ContractlessStandardResolver 245.2 ns NA 0.0150 64 B
MessagePackSerializer_Serialize_TypelessContractlessStandardResolver_primitive 210.6 ns NA 0.0188 80 B
MessagePackSerializer_Serialize_TypelessContractlessStandardResolver_complex 318.5 ns NA 0.0319 136 B

Deserialize

Method Mean Error Gen 0 Allocated
Old_MessagePackSerializer_Deserialize_StandardResolver 171.8 ns NA 0.0341 144 B
Old_MessagePackSerializer_Deserialize_ContractlessStandardResolver 308.0 ns NA 0.0339 144 B
Old_MessagePackSerializer_Deserialize_TypelessContractlessStandardResolver 169.8 ns NA 0.0226 96 B
Old_MessagePackSerializer_Deserialize_TypelessContractlessStandardResolverComplexBytes 3,043.2 ns NA 0.0687 296 B
MessagePackSerializer_Deserialize_StandardResolver 165.7 ns NA 0.0341 144 B
MessagePackSerializer_Deserialize_ContractlessStandardResolver 309.5 ns NA 0.0339 144 B
MessagePackSerializer_Deserialize_TypelessContractlessStandardResolver 253.2 ns NA 0.0224 96 B
MessagePackSerializer_Deserialize_TypelessContractlessStandardResolverComplexBytes 446.4 ns NA 0.0339 144 B
@alexvaluyskiy

This comment has been minimized.

Show comment
Hide comment
@alexvaluyskiy

alexvaluyskiy Aug 21, 2017

@neuecc nice improvement. It is time to release a new version on nuget

alexvaluyskiy commented Aug 21, 2017

@neuecc nice improvement. It is time to release a new version on nuget

@neuecc

This comment has been minimized.

Show comment
Hide comment
@neuecc

neuecc Aug 23, 2017

Owner

I've released Ver 1.5.1 that includes this improvement.

Owner

neuecc commented Aug 23, 2017

I've released Ver 1.5.1 that includes this improvement.

@neuecc neuecc closed this Aug 24, 2017

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