Possible performance hit in UnitsNet.NumberExtensions and anywhere where boxing could happen #1060
ikijano
started this conversation in
Show and tell
Replies: 1 comment
-
Hi and thank you for the performance report. Would you be interested in attempting to improve this? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There is possible performance hit if application uses heavily NumberExtensions to construct quantities, current implementation causes unnecessary GC pressure by allocation memory and slows down application. I understand the fact that using generics makes easy to implement conversion and probably reduces size of library but with tradeoff higher memory and CPU consumption at runtime.
where first one is using current implementation and two variants
Please consider this specially in core part of UnitNet to avoid unnecessary value type boxing.
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/boxing-and-unboxing
code example in sharplab.io
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.18363.1256 (1909/November2019Update/19H2)
Intel Core i7-8665U CPU 1.90GHz (Coffee Lake), 1 CPU, 8 logical and 4 physical cores
.NET SDK=6.0.200-preview.22055.15
[Host] : .NET 5.0.14 (5.0.1422.5710), X64 RyuJIT
Job-JVVMWO : .NET 5.0.14 (5.0.1422.5710), X64 RyuJIT
IterationTime=1.0000 s
Beta Was this translation helpful? Give feedback.
All reactions