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

Revert "Minor cleanups for System.Runtime.Numerics (#53984)" #57297

Merged
merged 1 commit into from
Aug 12, 2021

Conversation

tannergooding
Copy link
Member

This resolves #57293

@ghost
Copy link

ghost commented Aug 12, 2021

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

Issue Details

This resolves #57293

Author: tannergooding
Assignees: -
Labels:

area-System.Numerics

Milestone: -

@stephentoub
Copy link
Member

Thanks, @tannergooding.

@tannergooding
Copy link
Member Author

Did some brief additional investigation and it looks like the only changes that really need to be reverted are the ones using C# indexing expressions.

The fixes to use BitOperations, HashCode, and the is pattern all look to be perf improvements as expected.

I'm leaning towards leaving them out of .NET 6 anyways and letting them back in for .NET 7 but would appreciate hearing from @stephentoub first.

@stephentoub
Copy link
Member

I'm leaning towards leaving them out of .NET 6 anyways and letting them back in for .NET 7 but would appreciate hearing from @stephentoub first.

I'm ok with either option. If you're confident the regression will go away just by reverting the indexing expression changes, great. If you want to back it all out and we can try again after we fork for .NET 7, great.

@tannergooding
Copy link
Member Author

tannergooding commented Aug 12, 2021

Here is a comparison of the three.

The biggest callouts are Multiply, Divide, Remainder, ToStringX, Parse which are perf improvements with or without the indexer change.

There look to be a couple of small regressions with the change still but its not clear if that's due to noise or not (they are within the error range, which is fairly large and it fluxuates a bit across separate runs).

Revert Everything

Method numberString arguments Mean Error StdDev Median Min Max Gen 0 Gen 1 Allocated
Ctor_ByteArray -2147483648 ? 9.678 ns 0.0607 ns 0.0506 ns 9.657 ns 9.634 ns 9.800 ns - - -
ToByteArray -2147483648 ? 9.111 ns 0.1624 ns 0.1440 ns 9.053 ns 8.915 ns 9.398 ns 0.0019 - 32 B
Parse -2147483648 ? 101.100 ns 0.6090 ns 0.5697 ns 100.947 ns 100.261 ns 102.253 ns 0.0078 - 136 B
ToStringX -2147483648 ? 42.146 ns 0.1575 ns 0.1473 ns 42.156 ns 41.929 ns 42.417 ns 0.0023 - 40 B
ToStringD -2147483648 ? 45.784 ns 0.5166 ns 0.4832 ns 45.667 ns 44.881 ns 46.553 ns 0.0089 - 152 B
Add ? 1024,1024 bits 33.648 ns 0.3559 ns 0.3155 ns 33.646 ns 33.186 ns 34.184 ns 0.0095 - 160 B
Subtract ? 1024,1024 bits 36.045 ns 0.4218 ns 0.3522 ns 36.097 ns 35.452 ns 36.631 ns 0.0090 - 152 B
Multiply ? 1024,1024 bits 702.988 ns 2.5928 ns 2.2985 ns 702.892 ns 697.637 ns 706.562 ns 0.0140 - 280 B
GreatestCommonDivisor ? 1024,1024 bits 3,949.969 ns 5.1185 ns 4.5374 ns 3,950.274 ns 3,941.977 ns 3,957.487 ns 0.0158 - 304 B
ModPow ? 1024,1024,64 bits 79,945.743 ns 277.6864 ns 216.7993 ns 79,964.768 ns 79,587.881 ns 80,289.911 ns - - 304 B
Divide ? 1024,512 bits 322.317 ns 2.1775 ns 1.9303 ns 322.468 ns 319.302 ns 326.115 ns 0.0052 - 96 B
Remainder ? 1024,512 bits 332.658 ns 1.5066 ns 1.4093 ns 332.484 ns 330.171 ns 335.115 ns 0.0133 - 240 B
Ctor_ByteArray 123 ? 6.139 ns 0.0100 ns 0.0093 ns 6.137 ns 6.124 ns 6.153 ns - - -
ToByteArray 123 ? 8.867 ns 0.1158 ns 0.1026 ns 8.872 ns 8.675 ns 9.012 ns 0.0019 - 32 B
Parse 123 ? 74.097 ns 0.2600 ns 0.2432 ns 74.081 ns 73.573 ns 74.585 ns 0.0060 - 104 B
ToStringX 123 ? 41.054 ns 0.2919 ns 0.2730 ns 40.952 ns 40.726 ns 41.698 ns 0.0019 - 32 B
ToStringD 123 ? 27.242 ns 0.1833 ns 0.1715 ns 27.138 ns 27.069 ns 27.587 ns 0.0018 - 32 B
Ctor_ByteArray 123456789012(...)901234567890 [200] ? 78.694 ns 2.6243 ns 3.0222 ns 77.379 ns 75.128 ns 82.845 ns 0.0067 - 112 B
ToByteArray 123456789012(...)901234567890 [200] ? 42.520 ns 0.2091 ns 0.1853 ns 42.540 ns 42.230 ns 42.824 ns 0.0067 - 112 B
Parse 123456789012(...)901234567890 [200] ? 1,025.941 ns 6.0589 ns 5.6675 ns 1,025.008 ns 1,017.403 ns 1,035.142 ns 0.0574 - 984 B
ToStringX 123456789012(...)901234567890 [200] ? 237.653 ns 1.9259 ns 1.8015 ns 237.617 ns 235.037 ns 240.270 ns 0.0213 - 360 B
ToStringD 123456789012(...)901234567890 [200] ? 757.199 ns 7.1730 ns 6.3586 ns 756.410 ns 749.740 ns 770.944 ns 0.0578 - 992 B
Add ? 16,16 bits 5.861 ns 0.0171 ns 0.0143 ns 5.861 ns 5.840 ns 5.886 ns - - -
Subtract ? 16,16 bits 5.867 ns 0.0098 ns 0.0077 ns 5.868 ns 5.856 ns 5.879 ns - - -
Multiply ? 16,16 bits 4.914 ns 0.0231 ns 0.0205 ns 4.911 ns 4.894 ns 4.966 ns - - -
GreatestCommonDivisor ? 16,16 bits 18.205 ns 0.0305 ns 0.0270 ns 18.207 ns 18.153 ns 18.249 ns - - -
ModPow ? 16,16,16 bits 43.505 ns 0.1480 ns 0.1155 ns 43.472 ns 43.381 ns 43.804 ns - - -
Divide ? 16,8 bits 4.942 ns 0.0056 ns 0.0047 ns 4.943 ns 4.935 ns 4.954 ns - - -
Remainder ? 16,8 bits 4.726 ns 0.0132 ns 0.0111 ns 4.726 ns 4.710 ns 4.751 ns - - -
ModPow ? 16384,16384,64 bits 1,499,889.735 ns 2,215.0719 ns 2,071.9796 ns 1,499,778.409 ns 1,497,460.227 ns 1,504,011.932 ns - - 2,227 B
Divide ? 65536,32768 bits 3,680,591.346 ns 6,134.7911 ns 5,122.8284 ns 3,679,181.250 ns 3,673,878.750 ns 3,691,503.750 ns - - 12,351 B
Remainder ? 65536,32768 bits 3,663,220.625 ns 3,998.3745 ns 3,544.4549 ns 3,663,740.000 ns 3,654,858.750 ns 3,667,637.500 ns - - 12,343 B
Add ? 65536,65536 bits 1,662.011 ns 21.1629 ns 19.7958 ns 1,651.773 ns 1,635.408 ns 1,702.708 ns 0.4849 0.0133 8,224 B
Subtract ? 65536,65536 bits 1,656.362 ns 18.2894 ns 15.2724 ns 1,653.587 ns 1,634.340 ns 1,688.861 ns 0.4878 0.0132 8,216 B
Multiply ? 65536,65536 bits 640,632.392 ns 1,519.4019 ns 1,268.7694 ns 640,081.771 ns 639,464.323 ns 643,866.406 ns 7.8125 - 153,522 B
GreatestCommonDivisor ? 65536,65536 bits 3,418,600.769 ns 8,007.0890 ns 6,686.2820 ns 3,419,720.000 ns 3,409,205.000 ns 3,429,538.750 ns - - 16,439 B

Revert Only Index

Method numberString arguments Mean Error StdDev Median Min Max Gen 0 Gen 1 Allocated
Ctor_ByteArray -2147483648 ? 10.002 ns 0.0274 ns 0.0229 ns 9.996 ns 9.971 ns 10.051 ns - - -
ToByteArray -2147483648 ? 8.986 ns 0.0725 ns 0.0605 ns 8.987 ns 8.892 ns 9.076 ns 0.0019 - 32 B
Parse -2147483648 ? 102.193 ns 1.2263 ns 1.1471 ns 102.085 ns 100.584 ns 103.967 ns 0.0079 - 136 B
ToStringX -2147483648 ? 43.033 ns 0.2849 ns 0.2526 ns 42.961 ns 42.750 ns 43.561 ns 0.0023 - 40 B
ToStringD -2147483648 ? 46.389 ns 0.6446 ns 0.6029 ns 46.220 ns 45.490 ns 47.368 ns 0.0089 - 152 B
Add ? 1024,1024 bits 34.891 ns 0.2778 ns 0.2599 ns 34.867 ns 34.428 ns 35.397 ns 0.0095 - 160 B
Subtract ? 1024,1024 bits 35.842 ns 0.4282 ns 0.3796 ns 35.808 ns 35.012 ns 36.405 ns 0.0090 - 152 B
Multiply ? 1024,1024 bits 695.992 ns 3.5595 ns 2.9723 ns 696.042 ns 691.735 ns 701.408 ns 0.0166 - 280 B
GreatestCommonDivisor ? 1024,1024 bits 3,969.384 ns 14.7039 ns 13.0347 ns 3,966.919 ns 3,953.904 ns 3,990.925 ns 0.0159 - 304 B
ModPow ? 1024,1024,64 bits 79,998.393 ns 454.2639 ns 424.9188 ns 79,878.763 ns 79,494.356 ns 80,881.441 ns - - 304 B
Divide ? 1024,512 bits 316.339 ns 0.9188 ns 0.7173 ns 316.421 ns 315.141 ns 317.352 ns 0.0051 - 96 B
Remainder ? 1024,512 bits 332.364 ns 2.4810 ns 2.3207 ns 332.359 ns 328.461 ns 336.727 ns 0.0135 - 240 B
Ctor_ByteArray 123 ? 6.134 ns 0.0134 ns 0.0112 ns 6.132 ns 6.120 ns 6.158 ns - - -
ToByteArray 123 ? 8.879 ns 0.0870 ns 0.0813 ns 8.899 ns 8.747 ns 8.996 ns 0.0019 - 32 B
Parse 123 ? 73.332 ns 0.5588 ns 0.5227 ns 73.175 ns 72.793 ns 74.477 ns 0.0060 - 104 B
ToStringX 123 ? 37.675 ns 0.2704 ns 0.2529 ns 37.703 ns 37.269 ns 38.116 ns 0.0018 - 32 B
ToStringD 123 ? 26.665 ns 0.2967 ns 0.2630 ns 26.568 ns 26.360 ns 27.295 ns 0.0019 - 32 B
Ctor_ByteArray 123456789012(...)901234567890 [200] ? 79.049 ns 2.6185 ns 2.9105 ns 79.381 ns 74.851 ns 83.878 ns 0.0067 - 112 B
ToByteArray 123456789012(...)901234567890 [200] ? 39.554 ns 0.2893 ns 0.2416 ns 39.527 ns 39.215 ns 40.072 ns 0.0066 - 112 B
Parse 123456789012(...)901234567890 [200] ? 1,028.472 ns 9.0274 ns 8.0026 ns 1,026.659 ns 1,019.239 ns 1,041.590 ns 0.0573 - 984 B
ToStringX 123456789012(...)901234567890 [200] ? 240.281 ns 1.9762 ns 1.8485 ns 240.693 ns 237.071 ns 243.093 ns 0.0211 - 360 B
ToStringD 123456789012(...)901234567890 [200] ? 756.602 ns 8.6378 ns 7.2129 ns 754.725 ns 748.358 ns 773.417 ns 0.0572 - 992 B
Add ? 16,16 bits 6.536 ns 0.0376 ns 0.0351 ns 6.534 ns 6.496 ns 6.600 ns - - -
Subtract ? 16,16 bits 6.519 ns 0.0320 ns 0.0284 ns 6.510 ns 6.491 ns 6.580 ns - - -
Multiply ? 16,16 bits 4.952 ns 0.0190 ns 0.0159 ns 4.950 ns 4.931 ns 4.993 ns - - -
GreatestCommonDivisor ? 16,16 bits 18.018 ns 0.3750 ns 0.3508 ns 18.233 ns 17.503 ns 18.368 ns - - -
ModPow ? 16,16,16 bits 43.379 ns 0.1208 ns 0.1071 ns 43.366 ns 43.234 ns 43.591 ns - - -
Divide ? 16,8 bits 4.732 ns 0.0290 ns 0.0257 ns 4.725 ns 4.703 ns 4.785 ns - - -
Remainder ? 16,8 bits 4.736 ns 0.0356 ns 0.0333 ns 4.722 ns 4.702 ns 4.815 ns - - -
ModPow ? 16384,16384,64 bits 1,521,425.568 ns 2,216.7847 ns 1,730.7197 ns 1,521,440.625 ns 1,517,647.727 ns 1,523,105.114 ns - - 2,227 B
Divide ? 65536,32768 bits 3,666,874.327 ns 3,199.2258 ns 2,671.4985 ns 3,666,316.250 ns 3,662,401.250 ns 3,671,861.250 ns - - 12,351 B
Remainder ? 65536,32768 bits 3,670,973.750 ns 10,393.5934 ns 8,679.1212 ns 3,670,017.500 ns 3,662,207.500 ns 3,693,665.000 ns - - 12,343 B
Add ? 65536,65536 bits 1,665.865 ns 23.4677 ns 21.9517 ns 1,667.677 ns 1,626.922 ns 1,705.640 ns 0.4867 0.0133 8,224 B
Subtract ? 65536,65536 bits 1,675.099 ns 31.5989 ns 29.5577 ns 1,669.926 ns 1,634.693 ns 1,741.707 ns 0.4854 0.0133 8,216 B
Multiply ? 65536,65536 bits 635,538.577 ns 2,714.9582 ns 2,267.1130 ns 635,865.250 ns 631,255.250 ns 640,199.750 ns 7.5000 - 153,521 B
GreatestCommonDivisor ? 65536,65536 bits 3,412,352.143 ns 4,750.0979 ns 4,210.8381 ns 3,411,764.375 ns 3,406,368.750 ns 3,420,442.500 ns - - 16,439 B

Revert Nothing

Method numberString arguments Mean Error StdDev Median Min Max Gen 0 Gen 1 Allocated
Ctor_ByteArray -2147483648 ? 10.154 ns 0.0535 ns 0.0474 ns 10.136 ns 10.103 ns 10.243 ns - - -
ToByteArray -2147483648 ? 9.262 ns 0.2138 ns 0.2000 ns 9.264 ns 9.006 ns 9.688 ns 0.0019 - 32 B
Parse -2147483648 ? 104.145 ns 0.8052 ns 0.7532 ns 104.231 ns 102.425 ns 105.559 ns 0.0077 - 136 B
ToStringX -2147483648 ? 46.144 ns 0.2905 ns 0.2717 ns 46.013 ns 45.731 ns 46.645 ns 0.0023 - 40 B
ToStringD -2147483648 ? 47.871 ns 0.9793 ns 1.0056 ns 47.991 ns 46.407 ns 49.867 ns 0.0091 - 152 B
Add ? 1024,1024 bits 35.440 ns 0.5658 ns 0.5292 ns 35.428 ns 34.732 ns 36.383 ns 0.0094 - 160 B
Subtract ? 1024,1024 bits 36.026 ns 0.3977 ns 0.3321 ns 36.008 ns 35.489 ns 36.583 ns 0.0090 - 152 B
Multiply ? 1024,1024 bits 693.154 ns 3.3479 ns 2.9678 ns 692.020 ns 689.646 ns 699.171 ns 0.0165 - 280 B
GreatestCommonDivisor ? 1024,1024 bits 3,986.855 ns 36.4456 ns 28.4543 ns 3,972.872 ns 3,954.846 ns 4,023.477 ns 0.0161 - 304 B
ModPow ? 1024,1024,64 bits 80,043.099 ns 583.4364 ns 545.7468 ns 79,950.870 ns 79,270.490 ns 81,153.286 ns - - 304 B
Divide ? 1024,512 bits 316.004 ns 2.7051 ns 2.3980 ns 316.358 ns 310.655 ns 319.091 ns 0.0050 - 96 B
Remainder ? 1024,512 bits 329.880 ns 1.7578 ns 1.4678 ns 330.003 ns 327.938 ns 333.229 ns 0.0132 - 240 B
Ctor_ByteArray 123 ? 6.107 ns 0.0449 ns 0.0420 ns 6.088 ns 6.065 ns 6.190 ns - - -
ToByteArray 123 ? 8.953 ns 0.1722 ns 0.1438 ns 8.966 ns 8.749 ns 9.260 ns 0.0019 - 32 B
Parse 123 ? 73.790 ns 1.1975 ns 1.1202 ns 73.907 ns 72.431 ns 75.696 ns 0.0060 - 104 B
ToStringX 123 ? 37.480 ns 0.3291 ns 0.2749 ns 37.437 ns 37.070 ns 38.134 ns 0.0018 - 32 B
ToStringD 123 ? 26.775 ns 0.3446 ns 0.3055 ns 26.679 ns 26.485 ns 27.507 ns 0.0019 - 32 B
Ctor_ByteArray 123456789012(...)901234567890 [200] ? 89.160 ns 1.0670 ns 0.9980 ns 89.226 ns 86.624 ns 90.681 ns 0.0064 - 112 B
ToByteArray 123456789012(...)901234567890 [200] ? 39.759 ns 0.5535 ns 0.4622 ns 39.764 ns 38.669 ns 40.241 ns 0.0067 - 112 B
Parse 123456789012(...)901234567890 [200] ? 1,025.571 ns 11.5787 ns 10.2642 ns 1,022.920 ns 1,009.767 ns 1,050.002 ns 0.0575 - 984 B
ToStringX 123456789012(...)901234567890 [200] ? 240.085 ns 2.3032 ns 1.9233 ns 240.272 ns 236.675 ns 243.308 ns 0.0215 - 360 B
ToStringD 123456789012(...)901234567890 [200] ? 762.774 ns 8.4194 ns 7.8755 ns 762.581 ns 749.865 ns 775.404 ns 0.0577 - 992 B
Add ? 16,16 bits 6.496 ns 0.0119 ns 0.0099 ns 6.494 ns 6.479 ns 6.514 ns - - -
Subtract ? 16,16 bits 6.512 ns 0.0263 ns 0.0219 ns 6.510 ns 6.484 ns 6.566 ns - - -
Multiply ? 16,16 bits 4.925 ns 0.0148 ns 0.0131 ns 4.921 ns 4.906 ns 4.959 ns - - -
GreatestCommonDivisor ? 16,16 bits 18.238 ns 0.0853 ns 0.0798 ns 18.236 ns 18.132 ns 18.420 ns - - -
ModPow ? 16,16,16 bits 43.386 ns 0.0609 ns 0.0509 ns 43.391 ns 43.298 ns 43.470 ns - - -
Divide ? 16,8 bits 4.730 ns 0.0401 ns 0.0335 ns 4.714 ns 4.707 ns 4.810 ns - - -
Remainder ? 16,8 bits 4.749 ns 0.0505 ns 0.0421 ns 4.733 ns 4.717 ns 4.855 ns - - -
ModPow ? 16384,16384,64 bits 1,533,904.025 ns 8,706.6061 ns 6,797.5453 ns 1,531,616.193 ns 1,525,246.023 ns 1,546,076.705 ns - - 2,227 B
Divide ? 65536,32768 bits 3,679,447.788 ns 15,929.9951 ns 13,302.2674 ns 3,673,905.000 ns 3,663,735.000 ns 3,706,188.750 ns - - 12,351 B
Remainder ? 65536,32768 bits 3,681,732.019 ns 6,965.6787 ns 5,816.6572 ns 3,680,603.750 ns 3,671,321.250 ns 3,693,056.250 ns - - 12,343 B
Add ? 65536,65536 bits 1,695.190 ns 26.9010 ns 22.4636 ns 1,690.463 ns 1,666.869 ns 1,752.041 ns 0.4852 0.0135 8,224 B
Subtract ? 65536,65536 bits 1,717.677 ns 32.3542 ns 30.2641 ns 1,707.454 ns 1,679.262 ns 1,788.086 ns 0.4846 0.0135 8,216 B
Multiply ? 65536,65536 bits 631,423.404 ns 1,073.9314 ns 896.7814 ns 631,370.750 ns 629,889.000 ns 633,375.250 ns 7.5000 - 153,521 B
GreatestCommonDivisor ? 65536,65536 bits 3,469,162.857 ns 59,272.7645 ns 52,543.7618 ns 3,448,170.000 ns 3,426,277.500 ns 3,586,846.250 ns - - 16,440 B

@tannergooding tannergooding merged commit fcf276c into dotnet:main Aug 12, 2021
@sakno sakno mentioned this pull request Aug 16, 2021
8 tasks
sakno added a commit to sakno/runtime that referenced this pull request Aug 17, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 11, 2021
@tannergooding tannergooding deleted the fix-57293 branch November 11, 2022 15:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Perf] Regressions in System.Numerics.Tests.Perf_BigInteger
2 participants