Skip to content

[DNM][stdlib][ABI] Make default implementation for _rawHashValue(seed:) non-inlinable #20180

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

Closed
wants to merge 3 commits into from

Conversation

lorentey
Copy link
Member

Baking the default implementation into binaries prevents types from diverging top-level hashing from hash(into:) in future releases.

…paque

Allowing inlinability prevents types from customizing this in a way that changes the result.
@lorentey
Copy link
Member Author

This change might have interesting performance effects.

@swift-ci please benchmark

@lorentey
Copy link
Member Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
SetIsSubsetBox25 171 287 +67.8% 0.60x
SetIntersectionBox0 148 241 +62.8% 0.61x
SetIntersectionBox25 285 428 +50.2% 0.67x
Dictionary4OfObjects 322 481 +49.4% 0.67x
SetSubtractingBox0 160 239 +49.4% 0.67x
SetSymmetricDifferenceBox25 593 810 +36.6% 0.73x
SetSubtractingBox25 291 395 +35.7% 0.74x
SetSymmetricDifferenceBox0 732 981 +34.0% 0.75x
SetExclusiveOr_OfObjects 7315 9800 +34.0% 0.75x
Dictionary4 263 336 +27.8% 0.78x
SetUnionBox25 376 479 +27.4% 0.78x
SetUnionBox0 572 726 +26.9% 0.79x
SetUnion_OfObjects 5730 7263 +26.8% 0.79x
SetIsSubsetBox0 382 480 +25.7% 0.80x
Dictionary3OfObjects 534 650 +21.7% 0.82x
DictionarySwapOfObjects 7705 9202 +19.4% 0.84x
DictionarySubscriptDefaultMutationOfObjects 1494 1750 +17.1% 0.85x
CountAlgoString 2622 3029 +15.5% 0.87x
PrimsSplit 781 894 +14.5% 0.87x
Prims 781 889 +13.8% 0.88x
DictionarySwapAtOfObjects 7090 8043 +13.4% 0.88x
DictionaryRemoveOfObjects 21466 24024 +11.9% 0.89x
DictionaryGroupOfObjects 1990 2178 +9.4% 0.91x

Code size: -O

TEST OLD NEW DELTA RATIO
Regression
DictionaryRemove.o 15122 16786 +11.0% 0.90x
DictTest2.o 19692 21020 +6.7% 0.94x
DictionarySwap.o 27430 29094 +6.1% 0.94x
DictTest3.o 28348 29980 +5.8% 0.95x
RGBHistogram.o 24645 25989 +5.5% 0.95x
DictionarySubscriptDefault.o 30271 31743 +4.9% 0.95x
TestsUtils.o 24849 25937 +4.4% 0.96x
SetTests.o 59565 61309 +2.9% 0.97x
DictionaryGroup.o 17247 17695 +2.6% 0.97x
DictTest.o 51083 52363 +2.5% 0.98x
ReduceInto.o 24735 25071 +1.4% 0.99x
DictTest4.o 26046 26354 +1.2% 0.99x
WordCount.o 65320 66008 +1.1% 0.99x
Improvement
DictTest4Legacy.o 26936 26396 -2.0% 1.02x
ErrorHandling.o 2691 2643 -1.8% 1.02x
OpenClose.o 3823 3775 -1.3% 1.01x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
SetIsSubsetBox25 173 310 +79.2% 0.56x
SetIntersectionBox0 154 257 +66.9% 0.60x
SetSubtractingBox0 160 251 +56.9% 0.64x
SetIntersectionBox25 291 449 +54.3% 0.65x
Dictionary4 281 432 +53.7% 0.65x
Dictionary4OfObjects 344 523 +52.0% 0.66x
SetSymmetricDifferenceBox0 736 1043 +41.7% 0.71x
SetExclusiveOr_OfObjects 7362 10417 +41.5% 0.71x
SetSymmetricDifferenceBox25 596 834 +39.9% 0.71x
SetUnionBox0 582 779 +33.8% 0.75x
SetUnion_OfObjects 5825 7795 +33.8% 0.75x
SetSubtractingBox25 304 404 +32.9% 0.75x
SetUnionBox25 385 503 +30.6% 0.77x
SetIsSubsetBox0 386 503 +30.3% 0.77x
Dictionary4Legacy 617 747 +21.1% 0.83x
DictionaryRemoveOfObjects 21298 24463 +14.9% 0.87x
DictionarySubscriptDefaultMutationOfObjects 1550 1763 +13.7% 0.88x
CountAlgoString 2668 3025 +13.4% 0.88x
Dictionary4OfObjectsLegacy 751 847 +12.8% 0.89x
DictionarySwapOfObjects 8079 9091 +12.5% 0.89x
DictionarySwapAtOfObjects 7478 8094 +8.2% 0.92x

Code size: -Osize

TEST OLD NEW DELTA RATIO
Regression
DictionaryRemove.o 13983 14767 +5.6% 0.95x
DictionarySwap.o 25163 26331 +4.6% 0.96x
DictTest4.o 21199 22079 +4.2% 0.96x
RGBHistogram.o 22541 23277 +3.3% 0.97x
DictTest2.o 15958 16438 +3.0% 0.97x
DictionarySubscriptDefault.o 27079 27735 +2.4% 0.98x
ReduceInto.o 17179 17515 +2.0% 0.98x
StringRemoveDupes.o 8973 9117 +1.6% 0.98x
DictTest3.o 22486 22838 +1.6% 0.98x
AnyHashableWithAClass.o 3149 3197 +1.5% 0.98x
Improvement
DictTest4Legacy.o 22585 22105 -2.1% 1.02x

Code size: Swift libraries

TEST OLD NEW DELTA RATIO
Improvement
libswiftNetwork.dylib 163840 159744 -2.5% 1.03x
libswiftFoundation.dylib 1728512 1708032 -1.2% 1.01x
How to read the data The tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.

If you see any unexpected regressions, you should consider fixing the regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false alarms. Unexpected regressions which are marked with '(?)' are probably noise. If you see regressions which you cannot explain you can try to run the benchmarks again. If regressions still show up, please consult with the performance team (@eeckstein).

Hardware Overview
  Model Name: Mac Pro
  Model Identifier: MacPro6,1
  Processor Name: 12-Core Intel Xeon E5
  Processor Speed: 2.7 GHz
  Number of Processors: 1
  Total Number of Cores: 12
  L2 Cache (per Core): 256 KB
  L3 Cache: 30 MB
  Memory: 64 GB

@lorentey
Copy link
Member Author

lorentey commented Oct 31, 2018

That's not great, but it's what it is. The last commit combines this with a resilient Hasher; let's see what happens now.

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
SetIsSubsetBox25 153 278 +81.7% 0.55x
SetIntersectionBox0 133 227 +70.7% 0.59x
SetIntersectionBox25 258 395 +53.1% 0.65x
Dictionary4OfObjects 285 425 +49.1% 0.67x
SetSubtractingBox0 150 222 +48.0% 0.68x
SetSymmetricDifferenceBox25 539 758 +40.6% 0.71x
SetSymmetricDifferenceBox0 657 909 +38.4% 0.72x
SetExclusiveOr_OfObjects 6579 9096 +38.3% 0.72x
CountAlgoString 2394 3220 +34.5% 0.74x
SetIsSubsetInt50 138 184 +33.3% 0.75x
SetIsSubsetInt25 69 91 +31.9% 0.76x
SetSubtractingBox25 274 361 +31.8% 0.76x
SetUnion_OfObjects 5132 6745 +31.4% 0.76x
SetUnionBox0 513 674 +31.4% 0.76x
SetUnionBox25 338 443 +31.1% 0.76x
Dictionary4 233 305 +30.9% 0.76x
DictionaryGroup 195 254 +30.3% 0.77x
StringHashing_ascii 30 39 +30.0% 0.77x
SetIsSubsetBox0 350 452 +29.1% 0.77x
SetUnionInt100 63 81 +28.6% 0.78x
Dictionary 328 418 +27.4% 0.78x
SetSymmetricDifferenceInt25 187 238 +27.3% 0.79x
DictionarySwap 805 1024 +27.2% 0.79x
SetIsSubsetInt100 283 359 +26.9% 0.79x
SetIntersectionInt25 121 153 +26.4% 0.79x
Dictionary3OfObjects 474 597 +25.9% 0.79x
SetIntersectionInt0 59 74 +25.4% 0.80x
SetSubtractingInt25 92 115 +25.0% 0.80x
SetSubtractingInt0 66 82 +24.2% 0.80x
SetIntersect 604 745 +23.3% 0.81x
SetIntersectionInt50 181 223 +23.2% 0.81x
SetUnionInt25 96 118 +22.9% 0.81x
PrimsSplit 708 869 +22.7% 0.81x
SetExclusiveOr 2825 3460 +22.5% 0.82x
SetSymmetricDifferenceInt0 284 346 +21.8% 0.82x
StringHasPrefixUnicode 87417 105719 +20.9% 0.83x
SetUnion 2263 2726 +20.5% 0.83x
SetUnionInt0 226 272 +20.4% 0.83x
SetIntersectionInt100 298 357 +19.8% 0.83x
Dictionary3 145 172 +18.6% 0.84x
Dictionary4Legacy 551 653 +18.5% 0.84x
WordCountUniqueASCII 1435 1696 +18.2% 0.85x
StringMatch 6363 7492 +17.7% 0.85x (?)
DictionarySwapOfObjects 6921 8134 +17.5% 0.85x
DictionarySwapAt 910 1069 +17.5% 0.85x
SetUnionInt50 88 103 +17.0% 0.85x
DictionaryCompactMapValuesOfNilValue 4374 5108 +16.8% 0.86x
Dictionary4OfObjectsLegacy 686 798 +16.3% 0.86x
DictionaryFilter 39949 46373 +16.1% 0.86x
SetSubtractingInt100 139 161 +15.8% 0.86x
DictionarySwapAtOfObjects 6361 7364 +15.8% 0.86x
RGBHistogram 1862 2130 +14.4% 0.87x
DictionaryRemoveOfObjects 18840 21429 +13.7% 0.88x
Prims 705 801 +13.6% 0.88x
DictionaryRemove 2978 3377 +13.4% 0.88x (?)
StringHasSuffixUnicode 87612 98189 +12.1% 0.89x
DictionarySubscriptDefaultMutation 220 246 +11.8% 0.89x
DictionaryCopy 48498 53861 +11.1% 0.90x (?)
Dictionary2 534 593 +11.0% 0.90x
Chars2 2349 2606 +10.9% 0.90x
TwoSum 1046 1148 +9.8% 0.91x

Code size: -O

TEST OLD NEW DELTA RATIO
Regression
StringMatch.o 15991 41607 +160.2% 0.38x
StringRemoveDupes.o 15445 33690 +118.1% 0.46x
CountAlgo.o 20893 45318 +116.9% 0.46x
ReduceInto.o 24735 53223 +115.2% 0.46x
WordCount.o 65320 107874 +65.1% 0.61x
SuperChars.o 9350 13702 +46.5% 0.68x
RomanNumbers.o 11205 15253 +36.1% 0.73x
CSVParsing.o 45008 55635 +23.6% 0.81x
DictionaryRemove.o 15122 17122 +13.2% 0.88x
Substring.o 27833 31401 +12.8% 0.89x
DriverUtils.o 167991 188767 +12.4% 0.89x
Combos.o 16525 18237 +10.4% 0.91x
DictTest2.o 19692 21308 +8.2% 0.92x
Chars.o 12212 13172 +7.9% 0.93x
DictionarySwap.o 27430 29430 +7.3% 0.93x
DictTest3.o 28348 30324 +7.0% 0.93x
StringComparison.o 51900 55468 +6.9% 0.94x
RGBHistogram.o 24645 26293 +6.7% 0.94x
TestsUtils.o 24849 25937 +4.4% 0.96x
DictTest.o 51083 52651 +3.1% 0.97x
DictionarySubscriptDefault.o 30271 31199 +3.1% 0.97x
SetTests.o 59565 61309 +2.9% 0.97x
DictionaryGroup.o 17247 17695 +2.6% 0.97x
DictionaryCopy.o 8929 9120 +2.1% 0.98x
DictionaryCompactMapValues.o 22526 22958 +1.9% 0.98x
DictTest4.o 26046 26494 +1.7% 0.98x
Improvement
ErrorHandling.o 2691 2643 -1.8% 1.02x
DictTest4Legacy.o 26936 26536 -1.5% 1.02x
OpenClose.o 3823 3775 -1.3% 1.01x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
SetIsSubsetBox25 154 279 +81.2% 0.55x
SetIntersectionBox0 139 237 +70.5% 0.59x
SetSubtractingBox0 145 236 +62.8% 0.61x
SetIntersectionBox25 262 419 +59.9% 0.63x
SetSymmetricDifferenceBox0 663 971 +46.5% 0.68x
SetExclusiveOr_OfObjects 6638 9718 +46.4% 0.68x
Dictionary4OfObjects 308 450 +46.1% 0.68x
SetSymmetricDifferenceBox25 530 769 +45.1% 0.69x
Dictionary4 251 362 +44.2% 0.69x
SetIsSubsetInt50 149 214 +43.6% 0.70x
SetSubtractingBox25 261 371 +42.1% 0.70x
SetIsSubsetInt25 75 105 +40.0% 0.71x
SetUnionBox0 524 727 +38.7% 0.72x
SetUnion_OfObjects 5242 7269 +38.7% 0.72x
StringHashing_ascii 30 41 +36.7% 0.73x
SetIntersectionInt0 64 86 +34.4% 0.74x
SetIntersect 636 854 +34.3% 0.74x
SetUnionBox25 343 459 +33.8% 0.75x
Dictionary4Legacy 554 738 +33.2% 0.75x
SetIsSubsetInt100 293 390 +33.1% 0.75x
SetIsSubsetBox0 358 469 +31.0% 0.76x
SetUnionInt100 64 83 +29.7% 0.77x
SetSymmetricDifferenceInt25 199 255 +28.1% 0.78x
SetSubtractingInt50 112 143 +27.7% 0.78x
SetIntersectionInt25 135 171 +26.7% 0.79x
SetSubtractingInt0 70 88 +25.7% 0.80x
DictionarySwap 866 1084 +25.2% 0.80x
SetUnionInt25 100 125 +25.0% 0.80x
SetSymmetricDifferenceInt50 212 264 +24.5% 0.80x
CountAlgoString 2534 3153 +24.4% 0.80x
SetUnionInt50 87 108 +24.1% 0.81x
SetIntersectionInt50 202 249 +23.3% 0.81x
FrequenciesUsingReduceInto 1072 1316 +22.8% 0.81x
SetSubtractingInt25 93 114 +22.6% 0.82x
DictionarySwapOfObjects 6996 8570 +22.5% 0.82x
SetExclusiveOr 3008 3678 +22.3% 0.82x
SetSymmetricDifferenceInt0 300 366 +22.0% 0.82x
Dictionary 348 423 +21.6% 0.82x
SetIntersectionInt100 315 382 +21.3% 0.82x
StringMatch 6692 8108 +21.2% 0.83x (?)
DictionaryRemove 2976 3603 +21.1% 0.83x
StringHasPrefixUnicode 87233 105311 +20.7% 0.83x
Dictionary4OfObjectsLegacy 676 816 +20.7% 0.83x
SetSymmetricDifferenceInt100 198 239 +20.7% 0.83x
SetUnionInt0 240 288 +20.0% 0.83x
SetSubtractingInt100 140 168 +20.0% 0.83x
SetUnion 2402 2874 +19.7% 0.84x
DictionaryRemoveOfObjects 19131 22738 +18.9% 0.84x
Dictionary3 147 174 +18.4% 0.84x
WordCountUniqueASCII 1660 1953 +17.7% 0.85x
DictionaryFilter 41833 48725 +16.5% 0.86x
DictionaryCompactMapValuesOfNilValue 4569 5241 +14.7% 0.87x
PrimsSplit 775 888 +14.6% 0.87x
DictionaryGroup 291 332 +14.1% 0.88x
Chars2 2307 2631 +14.0% 0.88x
Prims 780 889 +14.0% 0.88x
DictionarySwapAtOfObjects 6454 7343 +13.8% 0.88x
DictionaryCopy 50370 57286 +13.7% 0.88x
Histogram 495 557 +12.5% 0.89x
RGBHistogramOfObjects 16382 18185 +11.0% 0.90x
TwoSum 1089 1204 +10.6% 0.90x
StringRemoveDupes 357 394 +10.4% 0.91x
Dictionary2 547 601 +9.9% 0.91x
Dictionary3OfObjects 606 661 +9.1% 0.92x
StringHasSuffixUnicode 90883 98348 +8.2% 0.92x
Improvement
SuperChars 19166 16981 -11.4% 1.13x

Code size: -Osize

TEST OLD NEW DELTA RATIO
Regression
StringMatch.o 7855 33575 +327.4% 0.23x
SuperChars.o 3407 11743 +244.7% 0.29x
StringRemoveDupes.o 8973 28298 +215.4% 0.32x
CountAlgo.o 14368 39037 +171.7% 0.37x
ReduceInto.o 17179 45472 +164.7% 0.38x
RomanNumbers.o 5806 13830 +138.2% 0.42x
Chars.o 5405 11469 +112.2% 0.47x
WordCount.o 54952 93594 +70.3% 0.59x
Combos.o 10749 16581 +54.3% 0.65x
Substring.o 20129 27619 +37.2% 0.73x
CSVParsing.o 37096 50483 +36.1% 0.73x
StringComparison.o 42388 49996 +17.9% 0.85x
DriverUtils.o 143811 162603 +13.1% 0.88x
DictionaryRemove.o 13983 14895 +6.5% 0.94x
DictionarySwap.o 25163 26475 +5.2% 0.95x
DictTest4.o 21199 22095 +4.2% 0.96x
DictTest2.o 15958 16598 +4.0% 0.96x
RGBHistogram.o 22541 23437 +4.0% 0.96x
DictionaryCopy.o 8137 8377 +2.9% 0.97x
DictTest3.o 22486 22998 +2.3% 0.98x
DictionaryCompactMapValues.o 21054 21470 +2.0% 0.98x
AnyHashableWithAClass.o 3149 3197 +1.5% 0.98x
DictTest.o 48437 49045 +1.3% 0.99x
RemoveWhere.o 24302 24606 +1.3% 0.99x
Improvement
DictTest4Legacy.o 22585 22121 -2.1% 1.02x
RangeAssignment.o 5229 5162 -1.3% 1.01x
DictionaryOfAnyHashableStrings.o 10109 9997 -1.1% 1.01x

Performance: -Onone

TEST OLD NEW DELTA RATIO
Regression
StringHasPrefixUnicode 90754 107996 +19.0% 0.84x
SetIsSubsetInt100 835 940 +12.6% 0.89x
SetIsSubsetInt25 239 269 +12.6% 0.89x
StringHasSuffixUnicode 90080 101374 +12.5% 0.89x
SetIntersectionInt50 513 577 +12.5% 0.89x
SetIntersectionInt100 816 895 +9.7% 0.91x
ExclusivityIndependent 63 68 +7.9% 0.93x
Improvement
Histogram 6077 5175 -14.8% 1.17x
ArrayOfPOD 766 695 -9.3% 1.10x (?)

Code size: Swift libraries

TEST OLD NEW DELTA RATIO
Regression
libswiftCore.dylib 3944448 4022272 +2.0% 0.98x
Improvement
libswiftSwiftPrivateLibcExtras.dylib 24576 20480 -16.7% 1.20x
libswiftNetwork.dylib 163840 159744 -2.5% 1.03x
How to read the data The tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.

If you see any unexpected regressions, you should consider fixing the regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false alarms. Unexpected regressions which are marked with '(?)' are probably noise. If you see regressions which you cannot explain you can try to run the benchmarks again. If regressions still show up, please consult with the performance team (@eeckstein).

Hardware Overview
  Model Name: Mac Pro
  Model Identifier: MacPro6,1
  Processor Name: 8-Core Intel Xeon E5
  Processor Speed: 3 GHz
  Number of Processors: 1
  Total Number of Cores: 8
  L2 Cache (per Core): 256 KB
  L3 Cache: 25 MB
  Memory: 64 GB

@lorentey lorentey changed the title [stdlib][ABI] Make default implementation for _rawHashValue(seed:) non-inlinable [DNM][stdlib][ABI] Make default implementation for _rawHashValue(seed:) non-inlinable Oct 31, 2018
@lorentey
Copy link
Member Author

Hm. I did not expect to see such code size regressions.

@airspeedswift
Copy link
Member

We should retest with the new String. I feel like taking the first one is OK (most of the regressions are just reclaiming perf wins vs 4.2), but not the resilient one due to the code size regressions.

@natecook1000
Copy link
Member

@lorentey Has this ship sailed? Or alternatively, did this land through another channel?

@shahmishal
Copy link
Member

Please update the base branch to main by Oct 5th otherwise the pull request will be closed automatically.

  • How to change the base branch: (Link)
  • More detail about the branch update: (Link)

@lorentey
Copy link
Member Author

lorentey commented Oct 2, 2020

Closing -- this ship has sailed a long time ago.

@lorentey lorentey closed this Oct 2, 2020
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.

5 participants