Skip to content

[stdlib][QoI] Replace recursion in sort _siftDown with Iteration #18629

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

Merged
merged 3 commits into from
Aug 17, 2018
Merged

[stdlib][QoI] Replace recursion in sort _siftDown with Iteration #18629

merged 3 commits into from
Aug 17, 2018

Conversation

kchibisov
Copy link
Contributor

stdlib sorting function uses recursion in it's supporting function called siftDown. We can replace recursion with iteration and reduce overhead.

@swift-ci please smoke benchmark

Iterative approach removes recursion overhead. Therefore performance
of sorting will be improved
@harlanhaskins
Copy link
Contributor

@Overlazy Thanks for taking the time to contribute! I've tagged @airspeedswift as a reviewer. In the meantime, I can ask CI to take a benchmark.

@swift-ci please smoke benchmark

@gottesmm
Copy link
Contributor

@harlanhaskins fyi, @airspeedswift is on vacation. You may want to tag someone else.

@airspeedswift
Copy link
Member

Thanks @gottesmm! That’s ok I can still review this one.

@swift-ci
Copy link
Contributor

Build comment file:

Optimized (O)

Regression (15)
TEST OLD NEW DELTA SPEEDUP
BinaryFloatingPointPropertiesBinade 25 31 +24.0% 0.81x
FatCompactMap 1247 1411 +13.2% 0.88x
ChainedFilterMap 1247 1408 +12.9% 0.89x
UTF8Decode_InitFromData_ascii 711 795 +11.8% 0.89x
UTF8Decode_InitFromBytes_ascii 500 559 +11.8% 0.89x
Calculator 199 220 +10.6% 0.90x
DictionarySwapAt 6405 7010 +9.4% 0.91x
DataCount 34 37 +8.8% 0.92x
ObjectiveCBridgeFromNSArrayAnyObjectForced 4950 5343 +7.9% 0.93x (?)
MapReduce 369 397 +7.6% 0.93x
NopDeinit 30160 32307 +7.1% 0.93x
PrefixAnySeqCRangeIterLazy 31 33 +6.5% 0.94x
PrefixAnySeqCRangeIter 31 33 +6.5% 0.94x
DictionaryBridge 1224 1297 +6.0% 0.94x (?)
BinaryFloatingPointPropertiesUlp 35 37 +5.7% 0.95x
Improvement (10)
TEST OLD NEW DELTA SPEEDUP
DropLastAnySeqCntRange 10 9 -10.0% 1.11x
COWTree 3932 3580 -9.0% 1.10x
MapReduceLazyCollectionShort 34 31 -8.8% 1.10x
DataReplaceSmallBuffer 9432 8829 -6.4% 1.07x (?)
DataSetCount 582 550 -5.5% 1.06x (?)
ObjectiveCBridgeFromNSSetAnyObject 52394 49543 -5.4% 1.06x (?)
ObjectiveCBridgeStubFromArrayOfNSString2 3784 3586 -5.2% 1.06x (?)
FrequenciesUsingReduce 5212 4944 -5.1% 1.05x (?)
DropFirstAnyCollectionLazy 68100 64615 -5.1% 1.05x
PrefixWhileSequence 345 328 -4.9% 1.05x
No Changes (420)
TEST OLD NEW DELTA SPEEDUP
AngryPhonebook 3774 3768 -0.2% 1.00x (?)
AnyHashableWithAClass 91197 91404 +0.2% 1.00x
Array2D 2720 2718 -0.1% 1.00x
ArrayAppend 802 799 -0.4% 1.00x (?)
ArrayAppendArrayOfInt 798 797 -0.1% 1.00x (?)
ArrayAppendAscii 3901 3934 +0.8% 0.99x (?)
ArrayAppendAsciiSubstring 24951 25006 +0.2% 1.00x
ArrayAppendFromGeneric 798 801 +0.4% 1.00x (?)
ArrayAppendGenericStructs 1438 1424 -1.0% 1.01x
ArrayAppendLatin1 40093 40154 +0.2% 1.00x
ArrayAppendLatin1Substring 142867 140599 -1.6% 1.02x
ArrayAppendLazyMap 1343 1336 -0.5% 1.01x (?)
ArrayAppendOptionals 1398 1431 +2.4% 0.98x (?)
ArrayAppendRepeatCol 1339 1339 +0.0% 1.00x
ArrayAppendReserved 529 529 +0.0% 1.00x
ArrayAppendSequence 1118 1119 +0.1% 1.00x (?)
ArrayAppendStrings 6339 6336 -0.0% 1.00x (?)
ArrayAppendToFromGeneric 801 797 -0.5% 1.01x (?)
ArrayAppendToGeneric 798 800 +0.3% 1.00x (?)
ArrayAppendUTF16 40585 40736 +0.4% 1.00x (?)
ArrayAppendUTF16Substring 141167 139746 -1.0% 1.01x
ArrayInClass 85 85 +0.0% 1.00x
ArrayLiteral 0 0 +0.0% 1.00x
ArrayOfGenericPOD2 152 152 +0.0% 1.00x
ArrayOfGenericRef 4326 4388 +1.4% 0.99x
ArrayOfPOD 186 187 +0.5% 0.99x
ArrayOfRef 4328 4342 +0.3% 1.00x (?)
ArrayPlusEqualArrayOfInt 798 797 -0.1% 1.00x (?)
ArrayPlusEqualFiveElementCollection 4245 4244 -0.0% 1.00x (?)
ArrayPlusEqualSingleElementCollection 798 799 +0.1% 1.00x (?)
ArrayPlusEqualThreeElements 1647 1648 +0.1% 1.00x (?)
ArraySubscript 1554 1571 +1.1% 0.99x (?)
ArrayValueProp 8 8 +0.0% 1.00x
ArrayValueProp2 8 8 +0.0% 1.00x
ArrayValueProp3 8 8 +0.0% 1.00x
ArrayValueProp4 8 8 +0.0% 1.00x
BinaryFloatingPointPropertiesNextUp 28 29 +3.6% 0.97x
BitCount 169 169 +0.0% 1.00x
ByteSwap 101 106 +5.0% 0.95x
COWArrayGuaranteedParameterOverhead 11122 11079 -0.4% 1.00x (?)
CSVParsing2 1714 1718 +0.2% 1.00x (?)
CSVParsingAlt2 1756 1771 +0.9% 0.99x (?)
CSVParsingAltIndices2 754 758 +0.5% 0.99x (?)
CStringLongAscii 3542 3559 +0.5% 1.00x
CStringLongNonAscii 2147 2202 +2.6% 0.98x (?)
CStringShortAscii 3167 3159 -0.3% 1.00x (?)
CaptureProp 4056 4065 +0.2% 1.00x (?)
CharIndexing_ascii_unicodeScalars 16614 16640 +0.2% 1.00x
CharIndexing_ascii_unicodeScalars_Backwards 16447 16444 -0.0% 1.00x (?)
CharIndexing_chinese_unicodeScalars 12592 12610 +0.1% 1.00x
CharIndexing_chinese_unicodeScalars_Backwards 12364 12364 +0.0% 1.00x
CharIndexing_japanese_unicodeScalars 19886 19902 +0.1% 1.00x (?)
CharIndexing_japanese_unicodeScalars_Backwards 19567 19571 +0.0% 1.00x (?)
CharIndexing_korean_unicodeScalars 16118 16124 +0.0% 1.00x (?)
CharIndexing_korean_unicodeScalars_Backwards 15858 15871 +0.1% 1.00x (?)
CharIndexing_punctuatedJapanese_unicodeScalars 3019 3027 +0.3% 1.00x
CharIndexing_punctuatedJapanese_unicodeScalars_Backwards 2971 2972 +0.0% 1.00x (?)
CharIndexing_punctuated_unicodeScalars 3772 3781 +0.2% 1.00x
CharIndexing_punctuated_unicodeScalars_Backwards 3710 3711 +0.0% 1.00x (?)
CharIndexing_russian_unicodeScalars 13850 13867 +0.1% 1.00x
CharIndexing_russian_unicodeScalars_Backwards 13701 13706 +0.0% 1.00x (?)
CharIndexing_tweet_unicodeScalars 32754 32914 +0.5% 1.00x
CharIndexing_tweet_unicodeScalars_Backwards 31592 31613 +0.1% 1.00x (?)
CharIndexing_utf16_unicodeScalars 22902 22785 -0.5% 1.01x
CharIndexing_utf16_unicodeScalars_Backwards 22981 22980 -0.0% 1.00x (?)
CharIteration_ascii_unicodeScalars 20272 20401 +0.6% 0.99x (?)
CharIteration_ascii_unicodeScalars_Backwards 15483 15492 +0.1% 1.00x
CharIteration_chinese_unicodeScalars 15335 15425 +0.6% 0.99x
CharIteration_chinese_unicodeScalars_Backwards 11729 11728 -0.0% 1.00x (?)
CharIteration_japanese_unicodeScalars 24240 24398 +0.7% 0.99x
CharIteration_japanese_unicodeScalars_Backwards 18530 18539 +0.0% 1.00x (?)
CharIteration_korean_unicodeScalars 19647 19752 +0.5% 0.99x
CharIteration_korean_unicodeScalars_Backwards 15027 15009 -0.1% 1.00x
CharIteration_punctuatedJapanese_unicodeScalars 3626 3658 +0.9% 0.99x
CharIteration_punctuatedJapanese_unicodeScalars_Backwards 2804 2804 +0.0% 1.00x
CharIteration_punctuated_unicodeScalars 4561 4590 +0.6% 0.99x
CharIteration_punctuated_unicodeScalars_Backwards 3507 3507 +0.0% 1.00x
CharIteration_russian_unicodeScalars 16859 16968 +0.6% 0.99x
CharIteration_russian_unicodeScalars_Backwards 12901 12896 -0.0% 1.00x (?)
CharIteration_tweet_unicodeScalars 39961 40252 +0.7% 0.99x
CharIteration_tweet_unicodeScalars_Backwards 30589 30572 -0.1% 1.00x (?)
CharIteration_utf16_unicodeScalars 27484 27558 +0.3% 1.00x
CharIteration_utf16_unicodeScalars_Backwards 18486 18444 -0.2% 1.00x
CharacterLiteralsLarge 5854 5925 +1.2% 0.99x
CharacterLiteralsSmall 217 220 +1.4% 0.99x
CharacterPropertiesFetch 4475 4508 +0.7% 0.99x (?)
CharacterPropertiesPrecomputed 982 973 -0.9% 1.01x (?)
CharacterPropertiesStashed 1703 1705 +0.1% 1.00x (?)
CharacterPropertiesStashedMemo 1456 1426 -2.1% 1.02x
Chars2 2636 2623 -0.5% 1.00x
ClassArrayGetter2 125 126 +0.8% 0.99x (?)
Combos 511 493 -3.5% 1.04x (?)
DataAccessBytes 1139 1138 -0.1% 1.00x (?)
DataAppendArray 5494 5507 +0.2% 1.00x (?)
DataAppendBytes 5317 5383 +1.2% 0.99x (?)
DataAppendDataLargeToLarge 70531 68791 -2.5% 1.03x (?)
DataAppendDataLargeToMedium 36026 35458 -1.6% 1.02x
DataAppendDataLargeToSmall 35097 35540 +1.3% 0.99x (?)
DataAppendDataMediumToLarge 38200 38479 +0.7% 0.99x (?)
DataAppendDataMediumToMedium 6878 6896 +0.3% 1.00x (?)
DataAppendDataMediumToSmall 6198 6152 -0.7% 1.01x (?)
DataAppendDataSmallToLarge 37579 37735 +0.4% 1.00x (?)
DataAppendDataSmallToMedium 6571 6508 -1.0% 1.01x (?)
DataAppendDataSmallToSmall 6118 6126 +0.1% 1.00x (?)
DataAppendSequence 21480 21370 -0.5% 1.01x (?)
DataCopyBytes 533 532 -0.2% 1.00x
DataMutateBytes 3878 3917 +1.0% 0.99x (?)
DataReplaceLarge 36697 36949 +0.7% 0.99x (?)
DataReplaceLargeBuffer 58933 59107 +0.3% 1.00x (?)
DataReplaceMedium 8151 8101 -0.6% 1.01x (?)
DataReplaceMediumBuffer 12851 13502 +5.1% 0.95x (?)
DataReplaceSmall 5807 5706 -1.7% 1.02x (?)
DataReset 2831 2819 -0.4% 1.00x (?)
DataSubscript 220 220 +0.0% 1.00x
DictOfArraysToArrayOfDicts 789 788 -0.1% 1.00x (?)
Dictionary 503 505 +0.4% 1.00x (?)
Dictionary2 622 623 +0.2% 1.00x (?)
Dictionary2OfObjects 2077 2068 -0.4% 1.00x (?)
Dictionary3 213 215 +0.9% 0.99x
Dictionary3OfObjects 730 731 +0.1% 1.00x (?)
Dictionary4 292 294 +0.7% 0.99x
Dictionary4Legacy 672 672 +0.0% 1.00x
Dictionary4OfObjects 413 416 +0.7% 0.99x
Dictionary4OfObjectsLegacy 996 999 +0.3% 1.00x (?)
DictionaryBridgeToObjC_Access 995 954 -4.1% 1.04x (?)
DictionaryBridgeToObjC_Bridge 19 19 +0.0% 1.00x
DictionaryBridgeToObjC_BulkAccess 164 170 +3.7% 0.96x
DictionaryCompactMapValuesOfCastValue 13590 13505 -0.6% 1.01x (?)
DictionaryCompactMapValuesOfNilValue 6519 6366 -2.3% 1.02x
DictionaryCopy 98813 98263 -0.6% 1.01x (?)
DictionaryFilter 98747 97561 -1.2% 1.01x (?)
DictionaryGroup 200 200 +0.0% 1.00x
DictionaryGroupOfObjects 2073 2071 -0.1% 1.00x (?)
DictionaryKeysContainsCocoa 39 40 +2.6% 0.98x
DictionaryKeysContainsNative 30 30 +0.0% 1.00x
DictionaryLiteral 1828 1828 +0.0% 1.00x
DictionaryOfObjects 2365 2360 -0.2% 1.00x (?)
DictionaryRemove 3737 3776 +1.0% 0.99x
DictionaryRemoveOfObjects 25025 25116 +0.4% 1.00x (?)
DictionarySubscriptDefaultMutation 245 244 -0.4% 1.00x (?)
DictionarySubscriptDefaultMutationArray 596 596 +0.0% 1.00x
DictionarySubscriptDefaultMutationArrayOfObjects 4010 3996 -0.3% 1.00x
DictionarySubscriptDefaultMutationOfObjects 1680 1693 +0.8% 0.99x
DictionarySwap 939 938 -0.1% 1.00x (?)
DictionarySwapAtOfObjects 51806 51891 +0.2% 1.00x (?)
DictionarySwapOfObjects 8639 8647 +0.1% 1.00x (?)
DoubleWidthDivision 0 0 +0.0% 1.00x
DropFirstAnyCollection 76 76 +0.0% 1.00x
DropFirstAnySeqCRangeIter 93 93 +0.0% 1.00x
DropFirstAnySeqCRangeIterLazy 93 93 +0.0% 1.00x
DropFirstAnySeqCntRange 71 71 +0.0% 1.00x
DropFirstAnySeqCntRangeLazy 71 71 +0.0% 1.00x
DropFirstAnySequence 1843 1842 -0.1% 1.00x (?)
DropFirstAnySequenceLazy 1841 1842 +0.1% 1.00x (?)
DropFirstArray 35 35 +0.0% 1.00x
DropFirstArrayLazy 35 35 +0.0% 1.00x
DropFirstCountableRange 29 29 +0.0% 1.00x
DropFirstCountableRangeLazy 29 29 +0.0% 1.00x
DropFirstSequence 2681 2680 -0.0% 1.00x (?)
DropFirstSequenceLazy 2774 2775 +0.0% 1.00x (?)
DropLastAnyCollection 28 28 +0.0% 1.00x
DropLastAnyCollectionLazy 21765 21670 -0.4% 1.00x (?)
DropLastAnySeqCRangeIter 3300 3308 +0.2% 1.00x
DropLastAnySeqCRangeIterLazy 3285 3300 +0.5% 1.00x (?)
DropLastAnySeqCntRangeLazy 9 9 +0.0% 1.00x
DropLastAnySequence 4946 4962 +0.3% 1.00x
DropLastAnySequenceLazy 5019 5053 +0.7% 0.99x
DropLastSequence 661 630 -4.7% 1.05x
DropLastSequenceLazy 659 632 -4.1% 1.04x
DropWhileAnyCollection 100 100 +0.0% 1.00x
DropWhileAnyCollectionLazy 147 147 +0.0% 1.00x
DropWhileAnySeqCRangeIter 75 75 +0.0% 1.00x
DropWhileAnySeqCRangeIterLazy 148 147 -0.7% 1.01x
DropWhileAnySeqCntRange 95 95 +0.0% 1.00x
DropWhileAnySeqCntRangeLazy 147 147 +0.0% 1.00x
DropWhileAnySequence 1854 1855 +0.1% 1.00x (?)
DropWhileAnySequenceLazy 1855 1856 +0.1% 1.00x (?)
DropWhileArrayLazy 105 105 +0.0% 1.00x
DropWhileCountableRange 30 30 +0.0% 1.00x
DropWhileCountableRangeLazy 82 82 +0.0% 1.00x
DropWhileSequence 2219 2208 -0.5% 1.00x
DropWhileSequenceLazy 105 105 +0.0% 1.00x
EqualStringSubstring 49 49 +0.0% 1.00x
EqualSubstringString 48 48 +0.0% 1.00x
EqualSubstringSubstring 48 48 +0.0% 1.00x
EqualSubstringSubstringGenericEquatable 48 48 +0.0% 1.00x
ErrorHandling 1202 1200 -0.2% 1.00x (?)
ExclusivityGlobal 5 5 +0.0% 1.00x
ExclusivityIndependent 2 2 +0.0% 1.00x
FilterEvenUsingReduce 1331 1341 +0.8% 0.99x (?)
FilterEvenUsingReduceInto 159 158 -0.6% 1.01x
FloatingPointPrinting_Double_description_small 21590 21652 +0.3% 1.00x (?)
FloatingPointPrinting_Double_description_uniform 21156 21345 +0.9% 0.99x (?)
FloatingPointPrinting_Double_interpolated 61283 61969 +1.1% 0.99x (?)
FloatingPointPrinting_Float80_description_small 28582 28506 -0.3% 1.00x (?)
FloatingPointPrinting_Float80_description_uniform 27617 27589 -0.1% 1.00x (?)
FloatingPointPrinting_Float80_interpolated 63992 64051 +0.1% 1.00x (?)
FloatingPointPrinting_Float_description_small 5730 5717 -0.2% 1.00x (?)
FloatingPointPrinting_Float_description_uniform 5644 5618 -0.5% 1.00x
FloatingPointPrinting_Float_interpolated 37754 37767 +0.0% 1.00x (?)
FrequenciesUsingReduceInto 1519 1506 -0.9% 1.01x (?)
Hanoi 2123 2137 +0.7% 0.99x
HashTest 973 947 -2.7% 1.03x
Histogram 588 592 +0.7% 0.99x (?)
Integrate 334 342 +2.4% 0.98x
IterateData 1451 1404 -3.2% 1.03x
Join 162 161 -0.6% 1.01x
LazilyFilteredArrayContains 35550 35891 +1.0% 0.99x
LazilyFilteredArrays2 4598 4567 -0.7% 1.01x
LazilyFilteredRange 3661 3764 +2.8% 0.97x
LessSubstringSubstring 48 48 +0.0% 1.00x
LessSubstringSubstringGenericComparable 48 48 +0.0% 1.00x
LinkedList 7571 7574 +0.0% 1.00x (?)
LuhnAlgoEager 445 452 +1.6% 0.98x (?)
LuhnAlgoLazy 449 442 -1.6% 1.02x (?)
MapReduceAnyCollection 371 369 -0.5% 1.01x (?)
MapReduceAnyCollectionShort 2005 2007 +0.1% 1.00x (?)
MapReduceClass 2984 2984 +0.0% 1.00x
MapReduceClassShort 4539 4516 -0.5% 1.01x
MapReduceLazyCollection 13 13 +0.0% 1.00x
MapReduceLazySequence 86 86 +0.0% 1.00x
MapReduceSequence 469 472 +0.6% 0.99x (?)
MapReduceShort 1975 1984 +0.5% 1.00x (?)
MapReduceShortString 21 21 +0.0% 1.00x
MapReduceString 47 45 -4.3% 1.04x
Memset 218 216 -0.9% 1.01x (?)
MonteCarloE 10247 10342 +0.9% 0.99x
MonteCarloPi 42854 42921 +0.2% 1.00x (?)
NSDictionaryCastToSwift 7192 7233 +0.6% 0.99x (?)
NSError 164 164 +0.0% 1.00x
NSStringConversion 687 690 +0.4% 1.00x
NibbleSort 3284 3280 -0.1% 1.00x (?)
ObjectAllocation 132 134 +1.5% 0.99x
ObjectiveCBridgeFromNSArrayAnyObject 27276 27324 +0.2% 1.00x (?)
ObjectiveCBridgeFromNSArrayAnyObjectToString 48636 49950 +2.7% 0.97x (?)
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 46531 45186 -2.9% 1.03x (?)
ObjectiveCBridgeFromNSDictionaryAnyObject 110941 113851 +2.6% 0.97x (?)
ObjectiveCBridgeFromNSSetAnyObjectForced 5064 5032 -0.6% 1.01x (?)
ObjectiveCBridgeFromNSSetAnyObjectToString 72945 73442 +0.7% 0.99x (?)
ObjectiveCBridgeFromNSString 1214 1218 +0.3% 1.00x (?)
ObjectiveCBridgeFromNSStringForced 2728 2865 +5.0% 0.95x (?)
ObjectiveCBridgeStubDataAppend 6480 6413 -1.0% 1.01x (?)
ObjectiveCBridgeStubDateMutation 400 400 +0.0% 1.00x
ObjectiveCBridgeStubFromNSString 1037 1035 -0.2% 1.00x (?)
ObjectiveCBridgeStubNSDataAppend 2603 2558 -1.7% 1.02x (?)
ObjectiveCBridgeStubToArrayOfNSString2 4001 3929 -1.8% 1.02x (?)
ObjectiveCBridgeStubToNSDate2 1606 1621 +0.9% 0.99x (?)
ObjectiveCBridgeStubToNSString 2357 2348 -0.4% 1.00x (?)
ObjectiveCBridgeStubToNSStringRef 121 125 +3.3% 0.97x
ObjectiveCBridgeStubURLAppendPath2 2959 2938 -0.7% 1.01x (?)
ObjectiveCBridgeStubURLAppendPathRef2 2894 2984 +3.1% 0.97x (?)
ObjectiveCBridgeToNSArray 14525 14410 -0.8% 1.01x (?)
ObjectiveCBridgeToNSDictionary 28574 28163 -1.4% 1.01x (?)
ObjectiveCBridgeToNSSet 18361 18818 +2.5% 0.98x (?)
ObjectiveCBridgeToNSString 450 452 +0.4% 1.00x
ObserverClosure 2163 2154 -0.4% 1.00x (?)
ObserverForwarderStruct 1190 1184 -0.5% 1.01x (?)
ObserverPartiallyAppliedMethod 3730 3715 -0.4% 1.00x (?)
ObserverUnappliedMethod 2444 2448 +0.2% 1.00x (?)
OpaqueConsumingUsers 4180 4181 +0.0% 1.00x (?)
OpenClose 71 68 -4.2% 1.04x
Phonebook 6993 7025 +0.5% 1.00x
PointerArithmetics 31490 31491 +0.0% 1.00x (?)
PolymorphicCalls 25 25 +0.0% 1.00x
PopFrontArray 1806 1792 -0.8% 1.01x (?)
PopFrontArrayGeneric 1817 1841 +1.3% 0.99x
PopFrontUnsafePointer 8706 8749 +0.5% 1.00x (?)
PrefixAnyCollection 76 76 +0.0% 1.00x
PrefixAnyCollectionLazy 65713 64483 -1.9% 1.02x (?)
PrefixAnySeqCntRange 71 71 +0.0% 1.00x
PrefixAnySeqCntRangeLazy 71 71 +0.0% 1.00x
PrefixAnySequence 1378 1378 +0.0% 1.00x
PrefixAnySequenceLazy 1378 1378 +0.0% 1.00x
PrefixArray 35 35 +0.0% 1.00x
PrefixArrayLazy 35 35 +0.0% 1.00x
PrefixCountableRange 29 29 +0.0% 1.00x
PrefixCountableRangeLazy 29 29 +0.0% 1.00x
PrefixSequence 2211 2224 +0.6% 0.99x
PrefixSequenceLazy 2275 2274 -0.0% 1.00x (?)
PrefixWhileAnyCollection 146 147 +0.7% 0.99x
PrefixWhileAnyCollectionLazy 89 89 +0.0% 1.00x
PrefixWhileAnySeqCRangeIter 385 368 -4.4% 1.05x
PrefixWhileAnySeqCRangeIterLazy 89 89 +0.0% 1.00x
PrefixWhileAnySequence 1532 1525 -0.5% 1.00x
PrefixWhileAnySequenceLazy 1391 1391 +0.0% 1.00x
PrefixWhileArray 88 88 +0.0% 1.00x
PrefixWhileArrayLazy 70 70 +0.0% 1.00x
PrefixWhileSequenceLazy 52 52 +0.0% 1.00x
Prims 900 897 -0.3% 1.00x (?)
PrimsSplit 895 898 +0.3% 1.00x (?)
QueueConcrete 1136 1136 +0.0% 1.00x
QueueGeneric 1128 1128 +0.0% 1.00x
RC4 154 155 +0.6% 0.99x
RGBHistogram 2388 2437 +2.1% 0.98x
RGBHistogramOfObjects 19957 20130 +0.9% 0.99x
Radix2CooleyTukey 12542 12191 -2.8% 1.03x (?)
Radix2CooleyTukeyf 8938 8849 -1.0% 1.01x (?)
RandomDoubleDef 26781 26767 -0.1% 1.00x (?)
RandomDoubleLCG 2032 2091 +2.9% 0.97x
RandomIntegersDef 24572 24302 -1.1% 1.01x
RandomIntegersLCG 178 178 +0.0% 1.00x
RandomShuffleDef2 2585 2598 +0.5% 0.99x (?)
RandomShuffleLCG2 1817 1815 -0.1% 1.00x
RangeAssignment 350 352 +0.6% 0.99x (?)
RangeIterationSigned 200 200 +0.0% 1.00x
RangeReplaceableCollectionPlusDefault 1063 1060 -0.3% 1.00x (?)
RecursiveOwnedParameter 115 115 +0.0% 1.00x
RemoveWhereFilterInts 47 47 +0.0% 1.00x
RemoveWhereFilterString 242 240 -0.8% 1.01x (?)
RemoveWhereFilterStrings 436 436 +0.0% 1.00x
RemoveWhereMoveInts 14 14 +0.0% 1.00x
RemoveWhereMoveStrings 704 709 +0.7% 0.99x
RemoveWhereQuadraticInts 1284 1286 +0.2% 1.00x (?)
RemoveWhereQuadraticString 374 369 -1.3% 1.01x (?)
RemoveWhereQuadraticStrings 2752 2753 +0.0% 1.00x (?)
RemoveWhereSwapInts 20 20 +0.0% 1.00x
RemoveWhereSwapStrings 862 863 +0.1% 1.00x
ReversedArray2 200 200 +0.0% 1.00x
ReversedBidirectional 13831 13992 +1.2% 0.99x
ReversedDictionary2 317 318 +0.3% 1.00x
RomanNumbers 87443 88215 +0.9% 0.99x
SequenceAlgosAnySequence 12420 12523 +0.8% 0.99x
SequenceAlgosArray 1587 1574 -0.8% 1.01x
SequenceAlgosContiguousArray 1583 1574 -0.6% 1.01x (?)
SequenceAlgosList 1353 1351 -0.1% 1.00x (?)
SequenceAlgosRange 2577 2577 +0.0% 1.00x
SequenceAlgosUnfoldSequence 1105 1105 +0.0% 1.00x
SetExclusiveOr 4926 4843 -1.7% 1.02x
SetExclusiveOr_OfObjects 11317 11345 +0.2% 1.00x
SetIntersect 578 581 +0.5% 0.99x (?)
SetIntersect_OfObjects 1672 1676 +0.2% 1.00x (?)
SetIsSubsetOf 323 323 +0.0% 1.00x
SetIsSubsetOf_OfObjects 432 432 +0.0% 1.00x
SetUnion 4293 4209 -2.0% 1.02x
SetUnion_OfObjects 9818 9857 +0.4% 1.00x (?)
SevenBoom 837 840 +0.4% 1.00x (?)
Sim2DArray 312 312 +0.0% 1.00x
SortLargeExistentials 5469 5451 -0.3% 1.00x (?)
SortLettersInPlace 966 969 +0.3% 1.00x
SortSortedStrings 680 679 -0.1% 1.00x (?)
SortStrings 1466 1461 -0.3% 1.00x (?)
SortStringsUnicode 2065 2065 +0.0% 1.00x
StackPromo 24355 24390 +0.1% 1.00x (?)
StaticArray 9 9 +0.0% 1.00x
StrComplexWalk 1782 1783 +0.1% 1.00x (?)
StrToInt 3241 3241 +0.0% 1.00x
StringAdder 551 551 +0.0% 1.00x
StringBuilder 491 491 +0.0% 1.00x
StringBuilderLong 1248 1219 -2.3% 1.02x (?)
StringBuilderSmallReservingCapacity 501 501 +0.0% 1.00x
StringBuilderWithLongSubstring 1430 1420 -0.7% 1.01x (?)
StringComparison_abnormal 831 834 +0.4% 1.00x (?)
StringComparison_ascii 993 989 -0.4% 1.00x
StringComparison_emoji 855 856 +0.1% 1.00x (?)
StringComparison_fastPrenormal 856 850 -0.7% 1.01x
StringComparison_latin1 659 658 -0.2% 1.00x (?)
StringComparison_longSharedPrefix 951 949 -0.2% 1.00x
StringComparison_nonBMPSlowestPrenormal 1663 1682 +1.1% 0.99x
StringComparison_slowerPrenormal 1820 1815 -0.3% 1.00x (?)
StringComparison_zalgo 112877 112871 -0.0% 1.00x (?)
StringEdits 174883 173132 -1.0% 1.01x (?)
StringEnumRawValueInitialization 861 865 +0.5% 1.00x (?)
StringEqualPointerComparison 315 315 +0.0% 1.00x
StringFromLongWholeSubstring 21 21 +0.0% 1.00x
StringFromLongWholeSubstringGeneric 21 21 +0.0% 1.00x
StringHasPrefixAscii 2233 2233 +0.0% 1.00x
StringHasPrefixUnicode 99379 98881 -0.5% 1.01x (?)
StringHasSuffixAscii 2290 2290 +0.0% 1.00x
StringHasSuffixUnicode 99910 99541 -0.4% 1.00x (?)
StringHashing_abnormal 1372 1438 +4.8% 0.95x
StringHashing_ascii 34 34 +0.0% 1.00x
StringHashing_emoji 2044 2016 -1.4% 1.01x (?)
StringHashing_fastPrenormal 8516 8453 -0.7% 1.01x
StringHashing_latin1 2636 2632 -0.2% 1.00x (?)
StringHashing_longSharedPrefix 7790 7730 -0.8% 1.01x
StringHashing_nonBMPSlowestPrenormal 2188 2226 +1.7% 0.98x (?)
StringHashing_slowerPrenormal 2825 2793 -1.1% 1.01x (?)
StringHashing_zalgo 3548 3586 +1.1% 0.99x
StringInterpolation 9029 9079 +0.6% 0.99x (?)
StringInterpolationManySmallSegments 17612 17573 -0.2% 1.00x (?)
StringInterpolationSmall 3995 3973 -0.6% 1.01x
StringMatch 12299 12173 -1.0% 1.01x
StringRemoveDupes 487 475 -2.5% 1.03x (?)
StringUTF16Builder 2583 2551 -1.2% 1.01x
StringUTF16SubstringBuilder 5845 5613 -4.0% 1.04x (?)
StringWalk 1553 1544 -0.6% 1.01x
StringWithCString2 1786 1788 +0.1% 1.00x
StringWordBuilder 2273 2262 -0.5% 1.00x
StringWordBuilderReservingCapacity 1674 1663 -0.7% 1.01x
SubstringComparable 12 12 +0.0% 1.00x
SubstringEqualString 615 607 -1.3% 1.01x
SubstringEquatable 1408 1415 +0.5% 1.00x
SubstringFromLongString 10 10 +0.0% 1.00x
SubstringFromLongStringGeneric 74 74 +0.0% 1.00x
SuffixAnyCollection 28 28 +0.0% 1.00x
SuffixAnyCollectionLazy 22108 21506 -2.7% 1.03x (?)
SuffixAnySeqCRangeIter 3598 3598 +0.0% 1.00x
SuffixAnySeqCRangeIterLazy 3600 3597 -0.1% 1.00x (?)
SuffixAnySeqCntRange 14 14 +0.0% 1.00x
SuffixAnySeqCntRangeLazy 14 14 +0.0% 1.00x
SuffixAnySequence 4962 4964 +0.0% 1.00x (?)
SuffixAnySequenceLazy 5045 5048 +0.1% 1.00x (?)
SuffixSequence 3630 3607 -0.6% 1.01x
SuffixSequenceLazy 3627 3607 -0.6% 1.01x (?)
SumUsingReduce 97 97 +0.0% 1.00x
SumUsingReduceInto 96 97 +1.0% 0.99x
SuperChars 19160 19184 +0.1% 1.00x (?)
TwoSum 1366 1345 -1.5% 1.02x
TypeFlood 0 0 +0.0% 1.00x
UTF8Decode 299 300 +0.3% 1.00x
UTF8Decode_InitDecoding 1351 1349 -0.1% 1.00x (?)
UTF8Decode_InitDecoding_ascii 656 656 +0.0% 1.00x
UTF8Decode_InitFromBytes 1190 1185 -0.4% 1.00x (?)
UTF8Decode_InitFromData 1280 1309 +2.3% 0.98x
Walsh 405 407 +0.5% 1.00x (?)
WordCountHistogramASCII 6763 6776 +0.2% 1.00x (?)
WordCountHistogramUTF16 10336 10323 -0.1% 1.00x (?)
WordCountUniqueASCII 2030 2034 +0.2% 1.00x
WordCountUniqueUTF16 4792 4861 +1.4% 0.99x (?)
XorLoop 395 397 +0.5% 0.99x (?)
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

let countToIndex = elements.distance(from: range.lowerBound, to: index)
let countFromIndex = elements.distance(from: index, to: range.upperBound)
// Check if left child is within bounds. If not, return, because there are
var index = index
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest using i instead of index. Really, all these free functions ought to be converted to be extensions on MutableCollection where Self: RandomAccessCollection, and if that refactoring happens then index with clash with all the same-named methods on self.

while countToIndex + 1 < countFromIndex {
let left = elements.index(index, offsetBy: countToIndex + 1)
var largest = index
if (try areInIncreasingOrder(elements[largest], elements[left])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nit, and I realize you're imitating the style in the rest of the file (which I think predates 1.0): you don't have to put parentheses around conditions in an if.

elements.swapAt(index, largest)
index = largest
} else {
break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice if the variable updates could move up into the if so the break is the last line. It'd be even nicer if this list could be recast as a repeat/while so the break isn't necessary, but maybe that's not easily done.

@airspeedswift
Copy link
Member

Thanks for looking at this code @Overlazy! Looks like a lot of the code in this file is pretty out of date and badly needs some modernization by the look of it.

Apart from some minor points, my main concern is that the benchmarks didn't show any difference because we aren't benchmarking input that triggers the heap sort. In the test suite, it looks like the only time this path gets exercised is when it's forced via this makeQSortKiller function. It'd be good to confirm if the benchmarks similarly force it, and if not, add some benchmarks (in another PR to merge first) to make sure we're testing the performance of this path before and after.

I'd actually be pretty interested in whether this extra heap sort really brings a significant speed boost. Because we're paying a big price for it in terms of compilation and user code size – for sort to be efficient, it has to be fully specialized, and it's pretty huge. Ditching the heap sort part could be a big win for those factors if it isn't pulling its weight. Adding some benchmarks would be a big help in determining this.

@airspeedswift
Copy link
Member

@swift-ci please smoke benchmark

@airspeedswift
Copy link
Member

@swift-ci please test

@swiftlang swiftlang deleted a comment from swift-ci Aug 16, 2018
@swiftlang swiftlang deleted a comment from swift-ci Aug 16, 2018
@swift-ci
Copy link
Contributor

Build comment file:

Optimized (O)

Regression (9)
TEST OLD NEW DELTA SPEEDUP
RangeIterationSigned 171 200 +17.0% 0.86x
ReversedArray2 172 200 +16.3% 0.86x
FrequenciesUsingReduce 4774 5371 +12.5% 0.89x (?)
StaticArray 9 10 +11.1% 0.90x (?)
RemoveWhereFilterInts 44 48 +9.1% 0.92x
NSDictionaryCastToSwift 7225 7850 +8.7% 0.92x
PrefixWhileSequence 330 352 +6.7% 0.94x
ObjectiveCBridgeStubFromArrayOfNSString2 3191 3399 +6.5% 0.94x (?)
DictionaryBridgeToObjC_Access 919 978 +6.4% 0.94x (?)
Improvement (17)
TEST OLD NEW DELTA SPEEDUP
SortIntPyramid 20387 8757 -57.0% 2.33x
Sim2DArray 399 313 -21.6% 1.27x
SortAdjacentIntPyramids 11589 10232 -11.7% 1.13x
DataAppendArray 6016 5431 -9.7% 1.11x
DataReplaceSmallBuffer 10363 9443 -8.9% 1.10x (?)
ObjectiveCBridgeFromNSArrayAnyObjectToString 49706 46424 -6.6% 1.07x (?)
ObjectiveCBridgeFromNSSetAnyObjectForced 5396 5046 -6.5% 1.07x (?)
RemoveWhereMoveInts 16 15 -6.2% 1.07x
DropFirstAnyCollectionLazy 70464 66086 -6.2% 1.07x
PrefixAnySeqCRangeIterLazy 33 31 -6.1% 1.06x
PrefixAnySeqCRangeIter 33 31 -6.1% 1.06x
SuffixAnyCollectionLazy 23700 22296 -5.9% 1.06x
Calculator 220 207 -5.9% 1.06x
DropLastAnyCollectionLazy 23399 22213 -5.1% 1.05x (?)
UTF8Decode_InitFromData_ascii 851 809 -4.9% 1.05x (?)
SumUsingReduce 102 97 -4.9% 1.05x
SumUsingReduceInto 102 97 -4.9% 1.05x
No Changes (421)
TEST OLD NEW DELTA SPEEDUP
AngryPhonebook 3933 3825 -2.7% 1.03x (?)
AnyHashableWithAClass 90911 91024 +0.1% 1.00x (?)
Array2D 2719 2717 -0.1% 1.00x (?)
ArrayAppend 796 804 +1.0% 0.99x
ArrayAppendArrayOfInt 798 781 -2.1% 1.02x (?)
ArrayAppendAscii 3936 3968 +0.8% 0.99x (?)
ArrayAppendAsciiSubstring 24989 24988 -0.0% 1.00x (?)
ArrayAppendFromGeneric 799 790 -1.1% 1.01x (?)
ArrayAppendGenericStructs 1426 1428 +0.1% 1.00x (?)
ArrayAppendLatin1 40226 39443 -1.9% 1.02x
ArrayAppendLatin1Substring 140361 140548 +0.1% 1.00x (?)
ArrayAppendLazyMap 1336 1347 +0.8% 0.99x (?)
ArrayAppendOptionals 1431 1430 -0.1% 1.00x (?)
ArrayAppendRepeatCol 1342 1330 -0.9% 1.01x (?)
ArrayAppendReserved 525 525 +0.0% 1.00x
ArrayAppendSequence 1110 1122 +1.1% 0.99x
ArrayAppendStrings 6336 6341 +0.1% 1.00x
ArrayAppendToFromGeneric 799 803 +0.5% 1.00x (?)
ArrayAppendToGeneric 801 800 -0.1% 1.00x (?)
ArrayAppendUTF16 41329 40415 -2.2% 1.02x
ArrayAppendUTF16Substring 138368 138390 +0.0% 1.00x (?)
ArrayInClass 85 85 +0.0% 1.00x
ArrayLiteral 0 0 +0.0% 1.00x
ArrayOfGenericPOD2 152 152 +0.0% 1.00x
ArrayOfGenericRef 4380 4323 -1.3% 1.01x
ArrayOfPOD 185 185 +0.0% 1.00x
ArrayOfRef 4304 4328 +0.6% 0.99x (?)
ArrayPlusEqualArrayOfInt 799 800 +0.1% 1.00x (?)
ArrayPlusEqualFiveElementCollection 4241 4208 -0.8% 1.01x
ArrayPlusEqualSingleElementCollection 798 797 -0.1% 1.00x (?)
ArrayPlusEqualThreeElements 1641 1624 -1.0% 1.01x
ArraySubscript 1584 1572 -0.8% 1.01x (?)
ArrayValueProp 8 8 +0.0% 1.00x
ArrayValueProp2 8 8 +0.0% 1.00x
ArrayValueProp3 8 8 +0.0% 1.00x
ArrayValueProp4 8 8 +0.0% 1.00x
BinaryFloatingPointPropertiesBinade 31 31 +0.0% 1.00x
BinaryFloatingPointPropertiesNextUp 29 28 -3.4% 1.04x
BinaryFloatingPointPropertiesUlp 37 37 +0.0% 1.00x
BitCount 169 169 +0.0% 1.00x
ByteSwap 106 107 +0.9% 0.99x
COWArrayGuaranteedParameterOverhead 11728 11586 -1.2% 1.01x (?)
COWTree 3810 3769 -1.1% 1.01x (?)
CSVParsing2 1717 1714 -0.2% 1.00x (?)
CSVParsingAlt2 1796 1790 -0.3% 1.00x (?)
CSVParsingAltIndices2 776 771 -0.6% 1.01x (?)
CStringLongAscii 3546 3539 -0.2% 1.00x (?)
CStringLongNonAscii 2134 2139 +0.2% 1.00x (?)
CStringShortAscii 3201 3168 -1.0% 1.01x (?)
CaptureProp 4088 4066 -0.5% 1.01x (?)
ChainedFilterMap 1408 1408 +0.0% 1.00x
CharIndexing_ascii_unicodeScalars 16765 16762 -0.0% 1.00x (?)
CharIndexing_ascii_unicodeScalars_Backwards 16249 16282 +0.2% 1.00x (?)
CharIndexing_chinese_unicodeScalars 12719 12790 +0.6% 0.99x
CharIndexing_chinese_unicodeScalars_Backwards 12288 12338 +0.4% 1.00x
CharIndexing_japanese_unicodeScalars 20061 20060 -0.0% 1.00x (?)
CharIndexing_japanese_unicodeScalars_Backwards 19441 19487 +0.2% 1.00x
CharIndexing_korean_unicodeScalars 16251 16251 +0.0% 1.00x
CharIndexing_korean_unicodeScalars_Backwards 15745 15803 +0.4% 1.00x
CharIndexing_punctuatedJapanese_unicodeScalars 3050 3032 -0.6% 1.01x
CharIndexing_punctuatedJapanese_unicodeScalars_Backwards 2928 2941 +0.4% 1.00x
CharIndexing_punctuated_unicodeScalars 3796 3801 +0.1% 1.00x (?)
CharIndexing_punctuated_unicodeScalars_Backwards 3666 3688 +0.6% 0.99x
CharIndexing_russian_unicodeScalars 13977 13958 -0.1% 1.00x
CharIndexing_russian_unicodeScalars_Backwards 13515 13581 +0.5% 1.00x
CharIndexing_tweet_unicodeScalars 32789 32696 -0.3% 1.00x (?)
CharIndexing_tweet_unicodeScalars_Backwards 31628 31461 -0.5% 1.01x (?)
CharIndexing_utf16_unicodeScalars 22811 22758 -0.2% 1.00x
CharIndexing_utf16_unicodeScalars_Backwards 22965 22986 +0.1% 1.00x (?)
CharIteration_ascii_unicodeScalars 20063 20227 +0.8% 0.99x
CharIteration_ascii_unicodeScalars_Backwards 14915 14916 +0.0% 1.00x (?)
CharIteration_chinese_unicodeScalars 15169 15338 +1.1% 0.99x (?)
CharIteration_chinese_unicodeScalars_Backwards 11293 11301 +0.1% 1.00x (?)
CharIteration_japanese_unicodeScalars 24072 24224 +0.6% 0.99x
CharIteration_japanese_unicodeScalars_Backwards 17861 17862 +0.0% 1.00x (?)
CharIteration_korean_unicodeScalars 19473 19632 +0.8% 0.99x
CharIteration_korean_unicodeScalars_Backwards 14460 14465 +0.0% 1.00x (?)
CharIteration_punctuatedJapanese_unicodeScalars 3595 3645 +1.4% 0.99x
CharIteration_punctuatedJapanese_unicodeScalars_Backwards 2700 2704 +0.1% 1.00x
CharIteration_punctuated_unicodeScalars 4504 4562 +1.3% 0.99x
CharIteration_punctuated_unicodeScalars_Backwards 3380 3386 +0.2% 1.00x
CharIteration_russian_unicodeScalars 16699 16855 +0.9% 0.99x
CharIteration_russian_unicodeScalars_Backwards 12430 12435 +0.0% 1.00x (?)
CharIteration_tweet_unicodeScalars 39870 40046 +0.4% 1.00x
CharIteration_tweet_unicodeScalars_Backwards 29105 28352 -2.6% 1.03x
CharIteration_utf16_unicodeScalars 27397 27388 -0.0% 1.00x (?)
CharIteration_utf16_unicodeScalars_Backwards 17471 17371 -0.6% 1.01x
CharacterLiteralsLarge 5831 5808 -0.4% 1.00x (?)
CharacterLiteralsSmall 220 220 +0.0% 1.00x
CharacterPropertiesFetch 4525 4499 -0.6% 1.01x (?)
CharacterPropertiesPrecomputed 969 964 -0.5% 1.01x (?)
CharacterPropertiesStashed 1718 1716 -0.1% 1.00x (?)
CharacterPropertiesStashedMemo 1442 1426 -1.1% 1.01x (?)
Chars2 2623 2624 +0.0% 1.00x (?)
ClassArrayGetter2 126 126 +0.0% 1.00x
Combos 495 502 +1.4% 0.99x (?)
DataAccessBytes 1171 1147 -2.0% 1.02x
DataAppendBytes 5635 5579 -1.0% 1.01x (?)
DataAppendDataLargeToLarge 69597 69892 +0.4% 1.00x (?)
DataAppendDataLargeToMedium 35936 35759 -0.5% 1.00x (?)
DataAppendDataLargeToSmall 34854 34948 +0.3% 1.00x (?)
DataAppendDataMediumToLarge 38508 38464 -0.1% 1.00x (?)
DataAppendDataMediumToMedium 6660 6896 +3.5% 0.97x (?)
DataAppendDataMediumToSmall 6085 6073 -0.2% 1.00x (?)
DataAppendDataSmallToLarge 37695 37947 +0.7% 0.99x (?)
DataAppendDataSmallToMedium 6572 6590 +0.3% 1.00x (?)
DataAppendDataSmallToSmall 6035 5825 -3.5% 1.04x (?)
DataAppendSequence 21748 21547 -0.9% 1.01x (?)
DataCopyBytes 530 529 -0.2% 1.00x
DataCount 37 37 +0.0% 1.00x
DataMutateBytes 4121 3964 -3.8% 1.04x
DataReplaceLarge 37113 36955 -0.4% 1.00x (?)
DataReplaceLargeBuffer 60140 58721 -2.4% 1.02x
DataReplaceMedium 8105 8170 +0.8% 0.99x (?)
DataReplaceMediumBuffer 13891 14250 +2.6% 0.97x (?)
DataReplaceSmall 5927 5865 -1.0% 1.01x
DataReset 2922 2913 -0.3% 1.00x (?)
DataSetCount 557 555 -0.4% 1.00x (?)
DataSubscript 220 220 +0.0% 1.00x
DictOfArraysToArrayOfDicts 789 797 +1.0% 0.99x (?)
Dictionary 508 497 -2.2% 1.02x
Dictionary2 622 622 +0.0% 1.00x
Dictionary2OfObjects 2065 2063 -0.1% 1.00x (?)
Dictionary3 214 212 -0.9% 1.01x
Dictionary3OfObjects 731 734 +0.4% 1.00x
Dictionary4 297 307 +3.4% 0.97x
Dictionary4Legacy 690 695 +0.7% 0.99x
Dictionary4OfObjects 419 423 +1.0% 0.99x (?)
Dictionary4OfObjectsLegacy 904 902 -0.2% 1.00x (?)
DictionaryBridge 1237 1266 +2.3% 0.98x (?)
DictionaryBridgeToObjC_Bridge 19 19 +0.0% 1.00x
DictionaryBridgeToObjC_BulkAccess 164 165 +0.6% 0.99x (?)
DictionaryCompactMapValuesOfCastValue 13898 13987 +0.6% 0.99x (?)
DictionaryCompactMapValuesOfNilValue 6523 6463 -0.9% 1.01x (?)
DictionaryCopy 98184 97803 -0.4% 1.00x (?)
DictionaryFilter 98415 98480 +0.1% 1.00x (?)
DictionaryGroup 201 202 +0.5% 1.00x (?)
DictionaryGroupOfObjects 2070 2072 +0.1% 1.00x (?)
DictionaryKeysContainsCocoa 38 39 +2.6% 0.97x (?)
DictionaryKeysContainsNative 30 30 +0.0% 1.00x
DictionaryLiteral 1833 1821 -0.7% 1.01x (?)
DictionaryOfObjects 2347 2357 +0.4% 1.00x (?)
DictionaryRemove 3719 3725 +0.2% 1.00x (?)
DictionaryRemoveOfObjects 25031 25108 +0.3% 1.00x (?)
DictionarySubscriptDefaultMutation 242 243 +0.4% 1.00x
DictionarySubscriptDefaultMutationArray 599 600 +0.2% 1.00x
DictionarySubscriptDefaultMutationArrayOfObjects 4007 3988 -0.5% 1.00x (?)
DictionarySubscriptDefaultMutationOfObjects 1670 1689 +1.1% 0.99x (?)
DictionarySwap 939 939 +0.0% 1.00x
DictionarySwapAt 6111 6245 +2.2% 0.98x
DictionarySwapAtOfObjects 51980 51854 -0.2% 1.00x (?)
DictionarySwapOfObjects 8586 8531 -0.6% 1.01x (?)
DoubleWidthDivision 0 0 +0.0% 1.00x
DropFirstAnyCollection 76 76 +0.0% 1.00x
DropFirstAnySeqCRangeIter 93 93 +0.0% 1.00x
DropFirstAnySeqCRangeIterLazy 93 93 +0.0% 1.00x
DropFirstAnySeqCntRange 71 71 +0.0% 1.00x
DropFirstAnySeqCntRangeLazy 71 71 +0.0% 1.00x
DropFirstAnySequence 1843 1842 -0.1% 1.00x
DropFirstAnySequenceLazy 1841 1841 +0.0% 1.00x
DropFirstArray 35 35 +0.0% 1.00x
DropFirstArrayLazy 35 35 +0.0% 1.00x
DropFirstCountableRange 29 29 +0.0% 1.00x
DropFirstCountableRangeLazy 29 29 +0.0% 1.00x
DropFirstSequence 2682 2682 +0.0% 1.00x
DropFirstSequenceLazy 2777 2775 -0.1% 1.00x
DropLastAnyCollection 28 28 +0.0% 1.00x
DropLastAnySeqCRangeIter 3303 3308 +0.2% 1.00x (?)
DropLastAnySeqCRangeIterLazy 3299 3311 +0.4% 1.00x
DropLastAnySeqCntRange 9 9 +0.0% 1.00x
DropLastAnySeqCntRangeLazy 9 9 +0.0% 1.00x
DropLastAnySequence 4965 4964 -0.0% 1.00x (?)
DropLastAnySequenceLazy 5048 5034 -0.3% 1.00x (?)
DropLastSequence 635 641 +0.9% 0.99x (?)
DropLastSequenceLazy 633 642 +1.4% 0.99x
DropWhileAnyCollection 100 100 +0.0% 1.00x
DropWhileAnyCollectionLazy 148 147 -0.7% 1.01x
DropWhileAnySeqCRangeIter 75 75 +0.0% 1.00x
DropWhileAnySeqCRangeIterLazy 147 147 +0.0% 1.00x
DropWhileAnySeqCntRange 95 95 +0.0% 1.00x
DropWhileAnySeqCntRangeLazy 147 147 +0.0% 1.00x
DropWhileAnySequence 1854 1855 +0.1% 1.00x (?)
DropWhileAnySequenceLazy 1855 1854 -0.1% 1.00x (?)
DropWhileArrayLazy 105 105 +0.0% 1.00x
DropWhileCountableRange 30 30 +0.0% 1.00x
DropWhileCountableRangeLazy 82 82 +0.0% 1.00x
DropWhileSequence 2208 2220 +0.5% 0.99x
DropWhileSequenceLazy 105 105 +0.0% 1.00x
EqualStringSubstring 48 48 +0.0% 1.00x
EqualSubstringString 49 48 -2.0% 1.02x
EqualSubstringSubstring 48 48 +0.0% 1.00x
EqualSubstringSubstringGenericEquatable 48 48 +0.0% 1.00x
ErrorHandling 1205 1192 -1.1% 1.01x
ExclusivityGlobal 5 5 +0.0% 1.00x
ExclusivityIndependent 2 2 +0.0% 1.00x
FatCompactMap 1408 1407 -0.1% 1.00x (?)
FilterEvenUsingReduce 1333 1371 +2.9% 0.97x
FilterEvenUsingReduceInto 160 159 -0.6% 1.01x (?)
FloatingPointPrinting_Double_description_small 21671 21603 -0.3% 1.00x (?)
FloatingPointPrinting_Double_description_uniform 21048 21085 +0.2% 1.00x (?)
FloatingPointPrinting_Double_interpolated 60682 61253 +0.9% 0.99x (?)
FloatingPointPrinting_Float80_description_small 28588 28537 -0.2% 1.00x (?)
FloatingPointPrinting_Float80_description_uniform 27756 27845 +0.3% 1.00x (?)
FloatingPointPrinting_Float80_interpolated 64293 64811 +0.8% 0.99x (?)
FloatingPointPrinting_Float_description_small 5998 5758 -4.0% 1.04x
FloatingPointPrinting_Float_description_uniform 5789 5629 -2.8% 1.03x
FloatingPointPrinting_Float_interpolated 38692 38357 -0.9% 1.01x (?)
FrequenciesUsingReduceInto 1504 1520 +1.1% 0.99x
Hanoi 2155 2175 +0.9% 0.99x (?)
HashTest 940 948 +0.9% 0.99x (?)
Histogram 583 589 +1.0% 0.99x
Integrate 345 342 -0.9% 1.01x
IterateData 1572 1597 +1.6% 0.98x
Join 162 162 +0.0% 1.00x
LazilyFilteredArrayContains 35858 35855 -0.0% 1.00x (?)
LazilyFilteredArrays2 4570 4567 -0.1% 1.00x (?)
LazilyFilteredRange 3769 3704 -1.7% 1.02x (?)
LessSubstringSubstring 48 48 +0.0% 1.00x
LessSubstringSubstringGenericComparable 48 48 +0.0% 1.00x
LinkedList 7578 7587 +0.1% 1.00x (?)
LuhnAlgoEager 444 442 -0.5% 1.00x (?)
LuhnAlgoLazy 445 440 -1.1% 1.01x (?)
MapReduce 398 398 +0.0% 1.00x
MapReduceAnyCollection 369 370 +0.3% 1.00x (?)
MapReduceAnyCollectionShort 2012 1989 -1.1% 1.01x (?)
MapReduceClass 2983 2988 +0.2% 1.00x (?)
MapReduceClassShort 4519 4523 +0.1% 1.00x (?)
MapReduceLazyCollection 13 13 +0.0% 1.00x
MapReduceLazyCollectionShort 31 31 +0.0% 1.00x
MapReduceLazySequence 86 86 +0.0% 1.00x
MapReduceSequence 474 481 +1.5% 0.99x (?)
MapReduceShort 1965 1967 +0.1% 1.00x (?)
MapReduceShortString 20 20 +0.0% 1.00x
MapReduceString 45 45 +0.0% 1.00x
Memset 217 219 +0.9% 0.99x (?)
MonteCarloE 10344 10281 -0.6% 1.01x
MonteCarloPi 42867 42638 -0.5% 1.01x
NSError 164 163 -0.6% 1.01x
NSStringConversion 684 687 +0.4% 1.00x
NibbleSort 3283 3285 +0.1% 1.00x
NopDeinit 32319 32306 -0.0% 1.00x
ObjectAllocation 133 132 -0.8% 1.01x
ObjectiveCBridgeFromNSArrayAnyObject 26599 26557 -0.2% 1.00x (?)
ObjectiveCBridgeFromNSArrayAnyObjectForced 5190 5112 -1.5% 1.02x (?)
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 44616 43324 -2.9% 1.03x (?)
ObjectiveCBridgeFromNSDictionaryAnyObject 112411 110267 -1.9% 1.02x (?)
ObjectiveCBridgeFromNSSetAnyObject 48773 49429 +1.3% 0.99x (?)
ObjectiveCBridgeFromNSSetAnyObjectToString 71958 71690 -0.4% 1.00x (?)
ObjectiveCBridgeFromNSString 1252 1246 -0.5% 1.00x (?)
ObjectiveCBridgeFromNSStringForced 2711 2711 +0.0% 1.00x
ObjectiveCBridgeStubDataAppend 6289 6215 -1.2% 1.01x (?)
ObjectiveCBridgeStubDateMutation 401 400 -0.2% 1.00x
ObjectiveCBridgeStubFromNSString 1034 1040 +0.6% 0.99x (?)
ObjectiveCBridgeStubNSDataAppend 2574 2607 +1.3% 0.99x (?)
ObjectiveCBridgeStubToArrayOfNSString2 4027 4150 +3.1% 0.97x (?)
ObjectiveCBridgeStubToNSDate2 1673 1635 -2.3% 1.02x (?)
ObjectiveCBridgeStubToNSString 2360 2347 -0.6% 1.01x (?)
ObjectiveCBridgeStubToNSStringRef 124 124 +0.0% 1.00x
ObjectiveCBridgeStubURLAppendPath2 2895 2899 +0.1% 1.00x (?)
ObjectiveCBridgeStubURLAppendPathRef2 2822 2814 -0.3% 1.00x (?)
ObjectiveCBridgeToNSArray 15220 15355 +0.9% 0.99x (?)
ObjectiveCBridgeToNSDictionary 28861 29149 +1.0% 0.99x (?)
ObjectiveCBridgeToNSSet 17898 18632 +4.1% 0.96x (?)
ObjectiveCBridgeToNSString 452 453 +0.2% 1.00x
ObserverClosure 2143 2142 -0.0% 1.00x (?)
ObserverForwarderStruct 1183 1189 +0.5% 0.99x (?)
ObserverPartiallyAppliedMethod 3685 3703 +0.5% 1.00x (?)
ObserverUnappliedMethod 2428 2426 -0.1% 1.00x (?)
OpaqueConsumingUsers 4179 4180 +0.0% 1.00x (?)
OpenClose 68 65 -4.4% 1.05x
Phonebook 7024 7048 +0.3% 1.00x
PointerArithmetics 31514 31484 -0.1% 1.00x (?)
PolymorphicCalls 25 25 +0.0% 1.00x
PopFrontArray 1793 1815 +1.2% 0.99x (?)
PopFrontArrayGeneric 1825 1812 -0.7% 1.01x (?)
PopFrontUnsafePointer 8746 8642 -1.2% 1.01x (?)
PrefixAnyCollection 76 76 +0.0% 1.00x
PrefixAnyCollectionLazy 66976 67187 +0.3% 1.00x (?)
PrefixAnySeqCntRange 71 71 +0.0% 1.00x
PrefixAnySeqCntRangeLazy 71 71 +0.0% 1.00x
PrefixAnySequence 1378 1378 +0.0% 1.00x
PrefixAnySequenceLazy 1379 1377 -0.1% 1.00x (?)
PrefixArray 35 35 +0.0% 1.00x
PrefixArrayLazy 35 35 +0.0% 1.00x
PrefixCountableRange 29 29 +0.0% 1.00x
PrefixCountableRangeLazy 29 29 +0.0% 1.00x
PrefixSequence 2211 2223 +0.5% 0.99x (?)
PrefixSequenceLazy 2275 2276 +0.0% 1.00x (?)
PrefixWhileAnyCollection 147 146 -0.7% 1.01x
PrefixWhileAnyCollectionLazy 89 89 +0.0% 1.00x
PrefixWhileAnySeqCRangeIter 371 389 +4.9% 0.95x
PrefixWhileAnySeqCRangeIterLazy 89 89 +0.0% 1.00x
PrefixWhileAnySequence 1529 1537 +0.5% 0.99x (?)
PrefixWhileAnySequenceLazy 1391 1392 +0.1% 1.00x (?)
PrefixWhileArray 88 88 +0.0% 1.00x
PrefixWhileArrayLazy 70 70 +0.0% 1.00x
PrefixWhileSequenceLazy 52 52 +0.0% 1.00x
Prims 902 905 +0.3% 1.00x (?)
PrimsSplit 895 910 +1.7% 0.98x (?)
QueueConcrete 1139 1141 +0.2% 1.00x
QueueGeneric 1130 1132 +0.2% 1.00x (?)
RC4 156 155 -0.6% 1.01x
RGBHistogram 2483 2432 -2.1% 1.02x
RGBHistogramOfObjects 20043 20082 +0.2% 1.00x (?)
Radix2CooleyTukey 12200 12476 +2.3% 0.98x (?)
Radix2CooleyTukeyf 8824 8729 -1.1% 1.01x (?)
RandomDoubleDef 26613 26689 +0.3% 1.00x
RandomDoubleLCG 2118 2177 +2.8% 0.97x
RandomIntegersDef 24508 24448 -0.2% 1.00x
RandomIntegersLCG 178 178 +0.0% 1.00x
RandomShuffleDef2 2588 2591 +0.1% 1.00x (?)
RandomShuffleLCG2 1809 1817 +0.4% 1.00x
RangeAssignment 336 351 +4.5% 0.96x
RangeReplaceableCollectionPlusDefault 1054 1053 -0.1% 1.00x (?)
RecursiveOwnedParameter 115 115 +0.0% 1.00x
RemoveWhereFilterString 241 240 -0.4% 1.00x (?)
RemoveWhereFilterStrings 437 438 +0.2% 1.00x
RemoveWhereMoveStrings 707 708 +0.1% 1.00x (?)
RemoveWhereQuadraticInts 1288 1288 +0.0% 1.00x
RemoveWhereQuadraticString 375 365 -2.7% 1.03x
RemoveWhereQuadraticStrings 2751 2754 +0.1% 1.00x
RemoveWhereSwapInts 20 20 +0.0% 1.00x
RemoveWhereSwapStrings 863 862 -0.1% 1.00x (?)
ReversedBidirectional 14015 14060 +0.3% 1.00x (?)
ReversedDictionary2 316 317 +0.3% 1.00x
RomanNumbers 87028 88708 +1.9% 0.98x
SequenceAlgosAnySequence 12393 12435 +0.3% 1.00x
SequenceAlgosArray 1580 1586 +0.4% 1.00x (?)
SequenceAlgosContiguousArray 1583 1578 -0.3% 1.00x (?)
SequenceAlgosList 1352 1354 +0.1% 1.00x (?)
SequenceAlgosRange 2576 2576 +0.0% 1.00x
SequenceAlgosUnfoldSequence 1105 1105 +0.0% 1.00x
SetExclusiveOr 4770 4811 +0.9% 0.99x
SetExclusiveOr_OfObjects 11312 11283 -0.3% 1.00x
SetIntersect 582 580 -0.3% 1.00x (?)
SetIntersect_OfObjects 1647 1723 +4.6% 0.96x
SetIsSubsetOf 323 323 +0.0% 1.00x
SetIsSubsetOf_OfObjects 432 434 +0.5% 1.00x
SetUnion 4104 4176 +1.8% 0.98x
SetUnion_OfObjects 9676 9700 +0.2% 1.00x
SevenBoom 833 837 +0.5% 1.00x (?)
SortLargeExistentials 5458 5440 -0.3% 1.00x
SortLettersInPlace 958 939 -2.0% 1.02x (?)
SortSortedStrings 677 702 +3.7% 0.96x
SortStrings 1450 1486 +2.5% 0.98x
SortStringsUnicode 2043 2057 +0.7% 0.99x
StackPromo 24417 24396 -0.1% 1.00x (?)
StrComplexWalk 1781 1780 -0.1% 1.00x (?)
StrToInt 3192 3162 -0.9% 1.01x
StringAdder 549 549 +0.0% 1.00x
StringBuilder 491 491 +0.0% 1.00x
StringBuilderLong 1230 1235 +0.4% 1.00x (?)
StringBuilderSmallReservingCapacity 500 501 +0.2% 1.00x
StringBuilderWithLongSubstring 1539 1472 -4.4% 1.05x (?)
StringComparison_abnormal 771 782 +1.4% 0.99x
StringComparison_ascii 962 994 +3.3% 0.97x
StringComparison_emoji 869 867 -0.2% 1.00x
StringComparison_fastPrenormal 852 846 -0.7% 1.01x
StringComparison_latin1 660 661 +0.2% 1.00x (?)
StringComparison_longSharedPrefix 950 952 +0.2% 1.00x (?)
StringComparison_nonBMPSlowestPrenormal 1696 1684 -0.7% 1.01x
StringComparison_slowerPrenormal 1858 1857 -0.1% 1.00x (?)
StringComparison_zalgo 111720 112061 +0.3% 1.00x (?)
StringEdits 172109 169191 -1.7% 1.02x (?)
StringEnumRawValueInitialization 863 864 +0.1% 1.00x (?)
StringEqualPointerComparison 314 315 +0.3% 1.00x
StringFromLongWholeSubstring 21 21 +0.0% 1.00x
StringFromLongWholeSubstringGeneric 21 21 +0.0% 1.00x
StringHasPrefixAscii 2262 2262 +0.0% 1.00x
StringHasPrefixUnicode 99301 98920 -0.4% 1.00x (?)
StringHasSuffixAscii 2263 2261 -0.1% 1.00x (?)
StringHasSuffixUnicode 99930 100098 +0.2% 1.00x (?)
StringHashing_abnormal 1341 1340 -0.1% 1.00x (?)
StringHashing_ascii 34 34 +0.0% 1.00x
StringHashing_emoji 1987 2014 +1.4% 0.99x (?)
StringHashing_fastPrenormal 8405 8397 -0.1% 1.00x (?)
StringHashing_latin1 2612 2570 -1.6% 1.02x (?)
StringHashing_longSharedPrefix 7730 7718 -0.2% 1.00x (?)
StringHashing_nonBMPSlowestPrenormal 2180 2223 +2.0% 0.98x (?)
StringHashing_slowerPrenormal 2739 2765 +0.9% 0.99x (?)
StringHashing_zalgo 3566 3544 -0.6% 1.01x
StringInterpolation 8874 8943 +0.8% 0.99x (?)
StringInterpolationManySmallSegments 17712 17820 +0.6% 0.99x (?)
StringInterpolationSmall 4023 4042 +0.5% 1.00x (?)
StringMatch 12265 12298 +0.3% 1.00x (?)
StringRemoveDupes 477 478 +0.2% 1.00x (?)
StringUTF16Builder 2529 2561 +1.3% 0.99x
StringUTF16SubstringBuilder 5869 5642 -3.9% 1.04x (?)
StringWalk 1629 1628 -0.1% 1.00x (?)
StringWithCString2 1786 1787 +0.1% 1.00x (?)
StringWordBuilder 2292 2283 -0.4% 1.00x
StringWordBuilderReservingCapacity 1640 1616 -1.5% 1.01x (?)
SubstringComparable 12 12 +0.0% 1.00x
SubstringEqualString 625 621 -0.6% 1.01x (?)
SubstringEquatable 1461 1460 -0.1% 1.00x (?)
SubstringFromLongString 10 10 +0.0% 1.00x
SubstringFromLongStringGeneric 74 74 +0.0% 1.00x
SuffixAnyCollection 28 28 +0.0% 1.00x
SuffixAnySeqCRangeIter 3592 3602 +0.3% 1.00x
SuffixAnySeqCRangeIterLazy 3597 3603 +0.2% 1.00x
SuffixAnySeqCntRange 14 14 +0.0% 1.00x
SuffixAnySeqCntRangeLazy 14 14 +0.0% 1.00x
SuffixAnySequence 4928 4973 +0.9% 0.99x (?)
SuffixAnySequenceLazy 5047 5061 +0.3% 1.00x (?)
SuffixSequence 3604 3592 -0.3% 1.00x (?)
SuffixSequenceLazy 3615 3614 -0.0% 1.00x (?)
SuperChars 19276 19554 +1.4% 0.99x
TwoSum 1354 1356 +0.1% 1.00x (?)
TypeFlood 0 0 +0.0% 1.00x
UTF8Decode 304 300 -1.3% 1.01x (?)
UTF8Decode_InitDecoding 1351 1352 +0.1% 1.00x (?)
UTF8Decode_InitDecoding_ascii 662 658 -0.6% 1.01x (?)
UTF8Decode_InitFromBytes 1211 1184 -2.2% 1.02x
UTF8Decode_InitFromBytes_ascii 513 497 -3.1% 1.03x (?)
UTF8Decode_InitFromData 1259 1276 +1.4% 0.99x
Walsh 409 406 -0.7% 1.01x
WordCountHistogramASCII 6907 6818 -1.3% 1.01x
WordCountHistogramUTF16 10234 10168 -0.6% 1.01x (?)
WordCountUniqueASCII 2055 2035 -1.0% 1.01x
WordCountUniqueUTF16 4580 4748 +3.7% 0.96x (?)
XorLoop 396 402 +1.5% 0.99x
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

@harlanhaskins
Copy link
Contributor

LLDB failure is unrelated.

@swift-ci please test

@kchibisov
Copy link
Contributor Author

@airspeedswift , do we need a separate PR without heapSort to compare performance?

@airspeedswift
Copy link
Member

@Overlazy looks like it made a significant difference, good spot!

Let's merge this, but yes, if you're interested, I definitely think it'd be worth seeing the impact of removing heap sort altogether.

If you're interested in a bigger challenge – ideally we would switch to a stable sort instead. Most stable sorts involve allocating memory, but it would be an interesting project to see how much of a difference that makes. Especially for sorted, where it needs to allocate anyway.

@airspeedswift airspeedswift merged commit 9c5f9ce into swiftlang:master Aug 17, 2018
@kchibisov kchibisov deleted the IterativeSiftInHeapSort branch August 17, 2018 00:45
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