Skip to content

[stdlib] Modify sort to pivot on median of 3 #6382

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 4 commits into from
Jan 6, 2017

Conversation

natecook1000
Copy link
Member

This modifies the internal _partition function used during sorting to select a better candidate as the pivot element. Currently, the first element of the range is always selected, leading to poor performance in cases of sorted or mostly sorted data. Benchmarks from this script for the current stdlib sort:

    data                        10000     100000    1000000
------------------------------------------------------------
01. random (wide):               0.01       0.12       1.51
02. random (4 items):            0.02       0.18       2.05
03. random runs (max):           0.01       0.13       1.53
04. random runs (4 items):       0.02       0.18       2.08
05. repeated runs:               0.02       0.19       2.09
06. steps:                       0.04       0.51       5.96
07. sorted:                      0.05       0.68       7.96
08. reversed:                    0.05       0.63       7.54
09. a few inserts:               0.05       0.67       7.91
10. new at end:                  0.05       0.68       7.98
11. qsort killer:                0.05       0.64       7.67

This revised partition function sorts the first, middle and last elements in the range, and then uses the new middle element as the pivot. Choosing the pivot in this way eliminates the poor performance (except for the QuickSort killer ¯\_(ツ)_/¯):

    data                        10000     100000    1000000
------------------------------------------------------------
01. random (wide):               0.01       0.13       1.61
02. random (4 items):            0.02       0.19       2.16
03. random runs (max):           0.01       0.13       1.60
04. random runs (4 items):       0.02       0.18       2.08
05. repeated runs:               0.02       0.18       2.09
06. steps:                       0.02       0.18       2.03
07. sorted:                      0.01       0.07       0.77
08. reversed:                    0.01       0.07       0.82
09. a few inserts:               0.01       0.13       1.60
10. new at end:                  0.01       0.11       1.37
11. qsort killer:                0.05       0.65       7.94

@natecook1000
Copy link
Member Author

@swift-ci Please smoke test

@natecook1000
Copy link
Member Author

@swift-ci Please benchmark

Copy link
Collaborator

@xwu xwu left a comment

Choose a reason for hiding this comment

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

Neato!

}
}

/// Reorders `elements` and returns an index `p` such that every element in
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: do you mean "returns an index pivot"?

// * elements[i] < pivot, for i in range.lowerBound..<lo
// * pivot <= elements[i] for i in hi..<range.upperBound
Loop: while true {
FindLo: repeat {
while lo != hi {
if !${cmp("elements[lo]", "pivot", p)} { break FindLo }
elements.formIndex(after: &lo)
}
break Loop
} while false
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I guess it's not really something you changed, but why repeat { } while false instead of just do { }?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm guessing this code predates introduction of do-catch—also, I didn't realize you could break from a do block. I've switched that, thanks!

@swift-ci
Copy link
Contributor

Build comment file:

Optimized (O)

Regression (5)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
StringHasPrefix 606 749 +23.6% 0.81x
Phonebook 6791 8024 +18.2% 0.85x
Calculator 28 32 +14.3% 0.88x
SortLettersInPlace 927 1002 +8.1% 0.93x(?)
OpenClose 49 52 +6.1% 0.94x(?)
Improvement (5)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
PopFrontArrayGeneric 1203 1112 -7.6% 1.08x(?)
PopFrontArray 1195 1098 -8.1% 1.09x(?)
MapReduce 360 331 -8.1% 1.09x(?)
ObjectiveCBridgeStubDateAccess 203 176 -13.3% 1.15x(?)
StaticArray 2699 478 -82.3% 5.65x
No Changes (137)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
AnyHashableWithAClass 64153 61638 -3.9% 1.04x(?)
DictionaryRemove 2305 2222 -3.6% 1.04x(?)
ArrayOfGenericRef 3549 3462 -2.5% 1.03x(?)
ArrayLiteral 1143 1125 -1.6% 1.02x(?)
ArrayInClass 64 63 -1.6% 1.02x(?)
ObjectiveCBridgeStubFromNSDate 3705 3633 -1.9% 1.02x(?)
Histogram 285 282 -1.1% 1.01x(?)
DictionaryBridge 3793 3759 -0.9% 1.01x(?)
ObjectiveCBridgeStubFromNSDateRef 3800 3755 -1.2% 1.01x(?)
DictionarySwapOfObjects 6004 5967 -0.6% 1.01x(?)
SuperChars 205083 202061 -1.5% 1.01x(?)
ObserverClosure 1904 1893 -0.6% 1.01x(?)
ProtocolDispatch 2971 2940 -1.0% 1.01x(?)
Dictionary3 504 497 -1.4% 1.01x(?)
Dictionary2 1973 1954 -1.0% 1.01x(?)
CaptureProp 4450 4403 -1.1% 1.01x(?)
RC4 159 158 -0.6% 1.01x(?)
UTF8Decode 276 274 -0.7% 1.01x(?)
SetExclusiveOr_OfObjects 7067 7025 -0.6% 1.01x(?)
ObjectiveCBridgeToNSDictionary 63336 62631 -1.1% 1.01x(?)
ObjectiveCBridgeStubNSDateMutationRef 12002 11923 -0.7% 1.01x(?)
StringHasPrefixUnicode 13927 13843 -0.6% 1.01x(?)
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 101028 100524 -0.5% 1.01x(?)
NSStringConversion 780 774 -0.8% 1.01x(?)
ArrayAppendSequence 1020 1014 -0.6% 1.01x(?)
DeadArray 179 178 -0.6% 1.01x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 89806 88836 -1.1% 1.01x(?)
MonteCarloPi 42490 42503 +0.0% 1.00x(?)
StackPromo 20338 20312 -0.1% 1.00x(?)
ObjectiveCBridgeFromNSDictionaryAnyObject 176027 175653 -0.2% 1.00x(?)
RecursiveOwnedParameter 1827 1825 -0.1% 1.00x(?)
Integrate 236 236 +0.0% 1.00x
ObjectiveCBridgeFromNSArrayAnyObjectToString 116674 117083 +0.3% 1.00x(?)
ClassArrayGetter 12 12 +0.0% 1.00x
Array2D 2023 2030 +0.3% 1.00x(?)
StringWithCString 146978 146631 -0.2% 1.00x(?)
ObjectiveCBridgeFromNSStringForced 2660 2648 -0.5% 1.00x(?)
Prims 706 707 +0.1% 1.00x(?)
DictionarySwap 404 402 -0.5% 1.00x(?)
Dictionary3OfObjects 836 832 -0.5% 1.00x(?)
RangeAssignment 284 284 +0.0% 1.00x
ByteSwap 0 0 +0.0% 1.00x
ArrayAppendGenericStructs 1145 1142 -0.3% 1.00x(?)
ArrayAppendLazyMap 835 833 -0.2% 1.00x(?)
ObjectiveCBridgeStubToNSDate 13135 13167 +0.2% 1.00x(?)
XorLoop 359 359 +0.0% 1.00x
StringInterpolation 10715 10760 +0.4% 1.00x(?)
ObjectiveCBridgeStubToNSString 1231 1233 +0.2% 1.00x(?)
ArrayAppendStrings 11426 11396 -0.3% 1.00x(?)
Join 445 446 +0.2% 1.00x(?)
ObjectAllocation 148 148 +0.0% 1.00x
TypeFlood 0 0 +0.0% 1.00x
ProtocolDispatch2 155 155 +0.0% 1.00x
StrComplexWalk 2812 2807 -0.2% 1.00x(?)
SetIntersect_OfObjects 1409 1410 +0.1% 1.00x(?)
ErrorHandling 2838 2832 -0.2% 1.00x(?)
ObjectiveCBridgeStubURLAppendPathRef 246157 246335 +0.1% 1.00x(?)
ObjectiveCBridgeToNSSet 40828 40828 +0.0% 1.00x
ArrayAppendOptionals 1144 1144 +0.0% 1.00x
NSError 312 312 +0.0% 1.00x
DictionaryOfObjects 2227 2232 +0.2% 1.00x(?)
ObjectiveCBridgeStubToNSDateRef 3292 3277 -0.5% 1.00x(?)
PopFrontUnsafePointer 8656 8694 +0.4% 1.00x(?)
StringEqualPointerComparison 7244 7253 +0.1% 1.00x(?)
PolymorphicCalls 20 20 +0.0% 1.00x
ArrayAppendReserved 514 512 -0.4% 1.00x(?)
ObjectiveCBridgeStubToNSStringRef 118 118 +0.0% 1.00x
ObjectiveCBridgeStubDateMutation 262 261 -0.4% 1.00x(?)
IterateData 2465 2466 +0.0% 1.00x(?)
ArrayOfGenericPOD 207 207 +0.0% 1.00x
DictionaryRemoveOfObjects 18426 18391 -0.2% 1.00x(?)
ObjectiveCBridgeStubURLAppendPath 245724 246475 +0.3% 1.00x(?)
SortStringsUnicode 8124 8101 -0.3% 1.00x(?)
SetIsSubsetOf 236 236 +0.0% 1.00x
Dictionary 697 697 +0.0% 1.00x
NopDeinit 35286 35161 -0.3% 1.00x(?)
ObjectiveCBridgeStubToArrayOfNSString 29144 29158 +0.1% 1.00x(?)
ObjectiveCBridgeFromNSArrayAnyObject 74788 75017 +0.3% 1.00x(?)
ObjectiveCBridgeStubDataAppend 3196 3181 -0.5% 1.00x(?)
NSDictionaryCastToSwift 4732 4711 -0.4% 1.00x(?)
ObjectiveCBridgeStubNSDateRefAccess 304 305 +0.3% 1.00x(?)
Sim2DArray 274 275 +0.4% 1.00x(?)
ArrayAppendRepeatCol 608 608 +0.0% 1.00x
MonteCarloE 9854 9878 +0.2% 1.00x(?)
SetUnion_OfObjects 5888 5900 +0.2% 1.00x(?)
StringHasSuffixUnicode 61991 62136 +0.2% 1.00x(?)
HashTest 1699 1695 -0.2% 1.00x(?)
SetIsSubsetOf_OfObjects 290 289 -0.3% 1.00x
ArrayAppend 733 731 -0.3% 1.00x(?)
LinkedList 6850 6848 -0.0% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectForced 4647 4658 +0.2% 1.00x(?)
ArrayAppendArrayOfInt 566 566 +0.0% 1.00x
ArrayOfPOD 172 172 +0.0% 1.00x
SetUnion 2318 2329 +0.5% 1.00x(?)
StringBuilder 1252 1254 +0.2% 1.00x(?)
ArrayValueProp2 5 5 +0.0% 1.00x
BitCount 1 1 +0.0% 1.00x
AngryPhonebook 2794 2782 -0.4% 1.00x(?)
SevenBoom 1305 1308 +0.2% 1.00x(?)
StringWalk 5554 5575 +0.4% 1.00x(?)
ArrayValueProp 5 5 +0.0% 1.00x
ObjectiveCBridgeStubFromArrayOfNSString 57508 57663 +0.3% 1.00x(?)
GlobalClass 0 0 +0.0% 1.00x
Memset 222 222 +0.0% 1.00x
Dictionary2OfObjects 3349 3347 -0.1% 1.00x(?)
ArrayValueProp4 5 5 +0.0% 1.00x
TwoSum 1276 1277 +0.1% 1.00x(?)
ArrayValueProp3 5 5 +0.0% 1.00x
ObserverPartiallyAppliedMethod 3249 3247 -0.1% 1.00x(?)
ArraySubscript 1367 1376 +0.7% 0.99x(?)
ObjectiveCBridgeToNSString 1045 1051 +0.6% 0.99x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 5368 5425 +1.1% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObjectForced 6131 6166 +0.6% 0.99x(?)
ObjectiveCBridgeFromNSSetAnyObject 83243 83673 +0.5% 0.99x(?)
ArrayOfRef 3408 3427 +0.6% 0.99x(?)
ObserverUnappliedMethod 2281 2296 +0.7% 0.99x(?)
ObjectiveCBridgeToNSArray 30282 30471 +0.6% 0.99x(?)
DictionaryLiteral 1240 1247 +0.6% 0.99x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 128462 129647 +0.9% 0.99x(?)
SetIntersect 350 352 +0.6% 0.99x(?)
SetExclusiveOr 2772 2789 +0.6% 0.99x(?)
Chars 603 608 +0.8% 0.99x(?)
ObserverForwarderStruct 862 874 +1.4% 0.99x(?)
ObjectiveCBridgeFromNSString 1766 1785 +1.1% 0.99x(?)
ObjectiveCBridgeStubNSDataAppend 2344 2362 +0.8% 0.99x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 199265 202497 +1.6% 0.98x(?)
ObjectiveCBridgeStubFromNSStringRef 128 131 +2.3% 0.98x(?)
ObjectiveCBridgeStubFromNSString 731 745 +1.9% 0.98x(?)
Walsh 309 314 +1.6% 0.98x(?)
RGBHistogramOfObjects 20386 20907 +2.6% 0.98x
StrToInt 4960 5050 +1.8% 0.98x(?)
RGBHistogram 2171 2249 +3.6% 0.97x(?)
146 3253148 3338861 +2.6% 0.97x
Hanoi 3068 3190 +4.0% 0.96x(?)
StringHasSuffix 781 817 +4.6% 0.96x(?)
SortStrings 1700 1788 +5.2% 0.95x(?)
ObjectiveCBridgeFromNSSetAnyObjectToString 135806 142629 +5.0% 0.95x(?)
**Unoptimized (Onone)**
Regression (3)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
SortLettersInPlace 2475 2725 +10.1% 0.91x
Phonebook 61882 68272 +10.3% 0.91x
TypeFlood 167 181 +8.4% 0.92x(?)
Improvement (3)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
ObjectiveCBridgeFromNSSetAnyObjectToString 160494 151278 -5.7% 1.06x(?)
ObjectiveCBridgeStubDateAccess 1148 1078 -6.1% 1.06x(?)
StaticArray 34203 11435 -66.6% 2.99x
No Changes (141)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
DictionaryBridge 3880 3777 -2.6% 1.03x(?)
DictionarySwap 5947 5778 -2.8% 1.03x(?)
Integrate 376 365 -2.9% 1.03x(?)
NSError 678 661 -2.5% 1.03x(?)
ObjectiveCBridgeFromNSArrayAnyObject 79099 76736 -3.0% 1.03x(?)
146 6190724 6000410 -3.1% 1.03x
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 213162 209011 -1.9% 1.02x(?)
SortStrings 2685 2640 -1.7% 1.02x
Prims 12808 12549 -2.0% 1.02x
ObjectiveCBridgeFromNSDictionaryAnyObject 185434 181926 -1.9% 1.02x(?)
ArrayAppend 3386 3322 -1.9% 1.02x(?)
ObjectiveCBridgeToNSArray 31036 30573 -1.5% 1.02x(?)
PolymorphicCalls 1170 1147 -2.0% 1.02x(?)
Dictionary 1828 1800 -1.5% 1.02x(?)
NopDeinit 61152 60209 -1.5% 1.02x(?)
NSDictionaryCastToSwift 6108 5988 -2.0% 1.02x(?)
ObjectiveCBridgeToNSDictionary 63622 62439 -1.9% 1.02x(?)
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 113523 111319 -1.9% 1.02x(?)
ArrayAppendSequence 103553 101368 -2.1% 1.02x
ArrayValueProp2 3118 3062 -1.8% 1.02x
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 92930 91116 -1.9% 1.02x(?)
ObjectiveCBridgeToNSString 1088 1077 -1.0% 1.01x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToString 124308 122798 -1.2% 1.01x(?)
Histogram 9744 9670 -0.8% 1.01x(?)
ObjectiveCBridgeStubFromNSDateRef 3929 3904 -0.6% 1.01x(?)
Dictionary3 1349 1336 -1.0% 1.01x(?)
RangeAssignment 12943 12865 -0.6% 1.01x(?)
ArrayAppendLazyMap 235410 233988 -0.6% 1.01x(?)
StringInterpolation 15429 15332 -0.6% 1.01x(?)
Join 1402 1390 -0.9% 1.01x(?)
StringHasSuffixUnicode 64592 63857 -1.1% 1.01x(?)
ObjectiveCBridgeFromNSSetAnyObject 89760 88835 -1.0% 1.01x(?)
DictionarySwapOfObjects 18672 18447 -1.2% 1.01x(?)
Dictionary2 3980 3951 -0.7% 1.01x(?)
Calculator 895 887 -0.9% 1.01x(?)
ObjectiveCBridgeStubDateMutation 482 476 -1.2% 1.01x(?)
ObjectiveCBridgeStubToArrayOfNSString 29520 29249 -0.9% 1.01x(?)
ObjectiveCBridgeStubNSDateRefAccess 1237 1228 -0.7% 1.01x(?)
ObjectiveCBridgeStubNSDateMutationRef 14116 14042 -0.5% 1.01x(?)
ObjectiveCBridgeToNSSet 41285 40887 -1.0% 1.01x(?)
StringHasPrefixUnicode 15674 15579 -0.6% 1.01x(?)
ArrayLiteral 1207 1192 -1.2% 1.01x(?)
Chars 4997 4962 -0.7% 1.01x(?)
StrToInt 5733 5678 -1.0% 1.01x(?)
BitCount 96 95 -1.0% 1.01x(?)
ArrayValueProp3 3017 3000 -0.6% 1.01x(?)
ArrayValueProp4 3039 3011 -0.9% 1.01x(?)
ArrayValueProp 2531 2502 -1.1% 1.01x(?)
ObjectiveCBridgeStubFromNSDate 3673 3648 -0.7% 1.01x(?)
ArraySubscript 5317 5342 +0.5% 1.00x(?)
MonteCarloPi 50599 50614 +0.0% 1.00x(?)
StackPromo 125052 125429 +0.3% 1.00x(?)
PopFrontArray 23262 23171 -0.4% 1.00x(?)
RecursiveOwnedParameter 10306 10285 -0.2% 1.00x(?)
ObjectiveCBridgeStubToNSString 1294 1290 -0.3% 1.00x(?)
ClassArrayGetter 1195 1195 +0.0% 1.00x
Array2D 766397 766779 +0.1% 1.00x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 7900 7902 +0.0% 1.00x(?)
OpenClose 450 449 -0.2% 1.00x(?)
StringWithCString 145852 145441 -0.3% 1.00x(?)
ObjectiveCBridgeFromNSArrayAnyObjectForced 10161 10145 -0.2% 1.00x(?)
ObjectiveCBridgeFromNSStringForced 3075 3066 -0.3% 1.00x(?)
Dictionary3OfObjects 1923 1918 -0.3% 1.00x(?)
StringHasPrefix 1551 1545 -0.4% 1.00x(?)
ByteSwap 9 9 +0.0% 1.00x
ArrayAppendGenericStructs 1187 1185 -0.2% 1.00x(?)
SuperChars 253893 253907 +0.0% 1.00x(?)
ObjectiveCBridgeStubToNSDate 13612 13573 -0.3% 1.00x(?)
XorLoop 18873 18880 +0.0% 1.00x(?)
ObserverClosure 6561 6554 -0.1% 1.00x(?)
ArrayAppendStrings 11103 11110 +0.1% 1.00x(?)
ObjectiveCBridgeStubFromNSStringRef 157 157 +0.0% 1.00x
ObjectiveCBridgeStubFromNSString 789 787 -0.2% 1.00x(?)
ObjectAllocation 539 537 -0.4% 1.00x(?)
AnyHashableWithAClass 77449 77633 +0.2% 1.00x(?)
ProtocolDispatch2 435 435 +0.0% 1.00x
HashTest 5048 5035 -0.3% 1.00x(?)
StrComplexWalk 7560 7547 -0.2% 1.00x(?)
SetIntersect_OfObjects 11649 11624 -0.2% 1.00x(?)
ErrorHandling 3736 3750 +0.4% 1.00x(?)
ObserverUnappliedMethod 8321 8336 +0.2% 1.00x(?)
ArrayAppendOptionals 1185 1185 +0.0% 1.00x
ObjectiveCBridgeStubToNSDateRef 3238 3222 -0.5% 1.00x(?)
PopFrontArrayGeneric 9263 9228 -0.4% 1.00x(?)
MapReduce 42622 42500 -0.3% 1.00x(?)
IterateData 10217 10259 +0.4% 1.00x(?)
DictionaryLiteral 15194 15180 -0.1% 1.00x(?)
Hanoi 18343 18267 -0.4% 1.00x(?)
DictionaryRemoveOfObjects 44641 44507 -0.3% 1.00x(?)
UTF8Decode 41098 41164 +0.2% 1.00x(?)
SortStringsUnicode 9241 9222 -0.2% 1.00x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 134640 135272 +0.5% 1.00x(?)
SetIsSubsetOf 2059 2058 -0.1% 1.00x(?)
ObjectiveCBridgeStubDataAppend 3383 3387 +0.1% 1.00x(?)
SetExclusiveOr 23069 23138 +0.3% 1.00x(?)
StringBuilder 2713 2722 +0.3% 1.00x(?)
ArrayInClass 3738 3739 +0.0% 1.00x(?)
ArrayOfGenericRef 9622 9578 -0.5% 1.00x(?)
StringHasSuffix 1539 1539 +0.0% 1.00x
Sim2DArray 14133 14096 -0.3% 1.00x(?)
SetExclusiveOr_OfObjects 38426 38297 -0.3% 1.00x(?)
MonteCarloE 102626 102522 -0.1% 1.00x(?)
SetUnion_OfObjects 26725 26837 +0.4% 1.00x(?)
RC4 8859 8857 -0.0% 1.00x(?)
Walsh 12665 12701 +0.3% 1.00x(?)
SetIsSubsetOf_OfObjects 1837 1835 -0.1% 1.00x(?)
DictionaryRemove 16326 16356 +0.2% 1.00x(?)
NSStringConversion 2942 2938 -0.1% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectForced 7510 7508 -0.0% 1.00x(?)
ArrayAppendArrayOfInt 603 602 -0.2% 1.00x(?)
SetUnion 11797 11808 +0.1% 1.00x(?)
ObserverForwarderStruct 4959 4942 -0.3% 1.00x(?)
DeadArray 117859 117732 -0.1% 1.00x(?)
AngryPhonebook 2958 2952 -0.2% 1.00x(?)
StringWalk 22542 22574 +0.1% 1.00x(?)
ObjectiveCBridgeFromNSString 5069 5066 -0.1% 1.00x(?)
GlobalClass 0 0 +0.0% 1.00x
Memset 19843 19787 -0.3% 1.00x(?)
ArrayAppendReserved 3128 3121 -0.2% 1.00x(?)
TwoSum 4848 4846 -0.0% 1.00x(?)
ObjectiveCBridgeStubNSDataAppend 2712 2703 -0.3% 1.00x(?)
ObserverPartiallyAppliedMethod 7895 7868 -0.3% 1.00x(?)
ProtocolDispatch 6321 6358 +0.6% 0.99x(?)
ArrayOfRef 8638 8701 +0.7% 0.99x(?)
ObjectiveCBridgeStubURLAppendPathRef 251985 253468 +0.6% 0.99x(?)
DictionaryOfObjects 4434 4458 +0.5% 0.99x(?)
PopFrontUnsafePointer 253389 255025 +0.7% 0.99x(?)
ObjectiveCBridgeStubToNSStringRef 149 150 +0.7% 0.99x(?)
ArrayOfGenericPOD 3431 3450 +0.6% 0.99x(?)
SetIntersect 12793 12886 +0.7% 0.99x(?)
RGBHistogramOfObjects 86640 87328 +0.8% 0.99x(?)
LinkedList 26030 26193 +0.6% 0.99x(?)
RGBHistogram 39199 39508 +0.8% 0.99x
ObjectiveCBridgeStubFromArrayOfNSString 57406 57741 +0.6% 0.99x(?)
Dictionary2OfObjects 5707 5745 +0.7% 0.99x(?)
SevenBoom 1463 1479 +1.1% 0.99x(?)
StringEqualPointerComparison 9556 9704 +1.6% 0.98x
CaptureProp 115265 118075 +2.4% 0.98x(?)
ObjectiveCBridgeStubURLAppendPath 245503 251160 +2.3% 0.98x(?)
ArrayAppendRepeatCol 212883 216991 +1.9% 0.98x(?)
ArrayOfPOD 2273 2364 +4.0% 0.96x
**Hardware Overview** Model Name: Mac mini Model Identifier: Macmini7,1 Processor Name: Intel Core i7 Processor Speed: 3 GHz Number of Processors: 1 Total Number of Cores: 2 L2 Cache (per Core): 256 KB L3 Cache: 4 MB Memory: 16 GB

@natecook1000
Copy link
Member Author

@swift-ci Please smoke test

@natecook1000
Copy link
Member Author

@swift-ci Please benchmark

1 similar comment
@natecook1000
Copy link
Member Author

@swift-ci Please benchmark

@gottesmm
Copy link
Contributor

@natecook1000 Can you add a benchmark that shows the bad perf? (Just so we can make sure we don't fall back into this).

@swift-ci
Copy link
Contributor

Build comment file:

Optimized (O)

Regression (6)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
StringHasPrefix 639 792 +23.9% 0.81x
OpenClose 51 60 +17.6% 0.85x
Calculator 30 33 +10.0% 0.91x
SortLettersInPlace 973 1042 +7.1% 0.93x
PopFrontUnsafePointer 9128 9741 +6.7% 0.94x
Phonebook 7116 7590 +6.7% 0.94x
Improvement (4)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
MapReduce 370 342 -7.6% 1.08x
SortStringsUnicode 8230 7261 -11.8% 1.13x
ObjectiveCBridgeStubDateAccess 212 182 -14.2% 1.16x
StaticArray 2694 469 -82.6% 5.74x
No Changes (137)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
SortStrings 1753 1699 -3.1% 1.03x
146 3122572 3045638 -2.5% 1.03x
ObjectiveCBridgeStubFromNSDateRef 3922 3858 -1.6% 1.02x
ObjectiveCBridgeStubToNSDate 13752 13446 -2.2% 1.02x(?)
ObjectiveCBridgeStubURLAppendPath 234487 230919 -1.5% 1.02x(?)
TwoSum 1332 1311 -1.6% 1.02x(?)
ObjectiveCBridgeStubFromNSDate 3835 3775 -1.6% 1.02x
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 206881 203984 -1.4% 1.01x(?)
Array2D 2045 2033 -0.6% 1.01x(?)
Histogram 290 286 -1.4% 1.01x(?)
ObjectiveCBridgeFromNSStringForced 2695 2678 -0.6% 1.01x(?)
ObserverClosure 2012 1997 -0.8% 1.01x(?)
ErrorHandling 2935 2908 -0.9% 1.01x(?)
ProtocolDispatch2 160 159 -0.6% 1.01x(?)
StrComplexWalk 2916 2893 -0.8% 1.01x(?)
ObjectiveCBridgeStubURLAppendPathRef 233668 232034 -0.7% 1.01x(?)
ObjectiveCBridgeToNSSet 40362 40049 -0.8% 1.01x(?)
RC4 166 165 -0.6% 1.01x(?)
SetUnion_OfObjects 6258 6224 -0.5% 1.01x(?)
ObjectiveCBridgeStubNSDateMutationRef 12406 12267 -1.1% 1.01x(?)
DictionaryRemove 2331 2300 -1.3% 1.01x(?)
ObjectiveCBridgeFromNSSetAnyObjectToString 139966 138986 -0.7% 1.01x(?)
StrToInt 5088 5050 -0.8% 1.01x
ArraySubscript 1452 1453 +0.1% 1.00x(?)
ObjectiveCBridgeToNSString 1074 1075 +0.1% 1.00x(?)
StackPromo 21546 21507 -0.2% 1.00x(?)
RecursiveOwnedParameter 1934 1934 +0.0% 1.00x
Integrate 238 238 +0.0% 1.00x
ClassArrayGetter 12 12 +0.0% 1.00x
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 5514 5516 +0.0% 1.00x(?)
MonteCarloPi 45002 45011 +0.0% 1.00x(?)
StringWithCString 198125 198742 +0.3% 1.00x(?)
ObjectiveCBridgeFromNSArrayAnyObjectForced 6100 6126 +0.4% 1.00x(?)
Prims 732 731 -0.1% 1.00x(?)
DictionarySwap 414 413 -0.2% 1.00x
ObjectiveCBridgeFromNSDictionaryAnyObject 178465 177628 -0.5% 1.00x(?)
Dictionary3OfObjects 872 871 -0.1% 1.00x(?)
ByteSwap 0 0 +0.0% 1.00x
SuperChars 212493 211872 -0.3% 1.00x(?)
XorLoop 380 380 +0.0% 1.00x
StringInterpolation 10918 10932 +0.1% 1.00x(?)
ObjectiveCBridgeStubToNSString 1281 1278 -0.2% 1.00x(?)
ArrayAppendStrings 12132 12124 -0.1% 1.00x(?)
ProtocolDispatch 3039 3040 +0.0% 1.00x(?)
TypeFlood 0 0 +0.0% 1.00x
ArrayLiteral 1177 1177 +0.0% 1.00x
Dictionary3 524 523 -0.2% 1.00x(?)
Dictionary2 2037 2039 +0.1% 1.00x(?)
SetIntersect_OfObjects 1495 1492 -0.2% 1.00x(?)
ArrayOfRef 3533 3549 +0.5% 1.00x(?)
ObserverUnappliedMethod 2432 2422 -0.4% 1.00x(?)
ObjectiveCBridgeToNSArray 30471 30436 -0.1% 1.00x(?)
NSError 324 325 +0.3% 1.00x(?)
DictionaryOfObjects 2295 2291 -0.2% 1.00x(?)
PopFrontArrayGeneric 1118 1119 +0.1% 1.00x(?)
StringEqualPointerComparison 7359 7360 +0.0% 1.00x(?)
CaptureProp 4563 4566 +0.1% 1.00x(?)
PolymorphicCalls 22 22 +0.0% 1.00x
ArrayAppendReserved 536 536 +0.0% 1.00x
ObjectiveCBridgeStubToNSStringRef 124 124 +0.0% 1.00x
ObjectiveCBridgeStubDateMutation 273 273 +0.0% 1.00x
AngryPhonebook 2831 2842 +0.4% 1.00x(?)
IterateData 2605 2610 +0.2% 1.00x(?)
DictionaryLiteral 1266 1266 +0.0% 1.00x
ArrayOfGenericPOD 220 220 +0.0% 1.00x
DictionaryRemoveOfObjects 19434 19374 -0.3% 1.00x(?)
UTF8Decode 288 288 +0.0% 1.00x
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 128906 129193 +0.2% 1.00x(?)
SetIsSubsetOf 250 250 +0.0% 1.00x
NopDeinit 36663 36667 +0.0% 1.00x(?)
ObjectiveCBridgeStubDataAppend 3376 3382 +0.2% 1.00x(?)
SetExclusiveOr 2897 2886 -0.4% 1.00x(?)
NSDictionaryCastToSwift 4958 4964 +0.1% 1.00x(?)
RGBHistogramOfObjects 21510 21454 -0.3% 1.00x(?)
ObjectiveCBridgeStubNSDateRefAccess 308 308 +0.0% 1.00x
StringBuilder 1312 1317 +0.4% 1.00x(?)
ArrayInClass 62 62 +0.0% 1.00x
ArrayOfGenericRef 3612 3613 +0.0% 1.00x(?)
Sim2DArray 277 277 +0.0% 1.00x
SetExclusiveOr_OfObjects 7470 7466 -0.1% 1.00x(?)
ArrayAppendRepeatCol 643 643 +0.0% 1.00x
ObjectiveCBridgeToNSDictionary 63005 62711 -0.5% 1.00x(?)
MonteCarloE 10451 10486 +0.3% 1.00x(?)
StringHasSuffixUnicode 63016 63208 +0.3% 1.00x(?)
SetIsSubsetOf_OfObjects 306 307 +0.3% 1.00x
ArrayAppend 775 776 +0.1% 1.00x(?)
StringHasPrefixUnicode 14220 14203 -0.1% 1.00x(?)
LinkedList 7255 7254 -0.0% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 102028 101568 -0.5% 1.00x(?)
NSStringConversion 807 803 -0.5% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectForced 4750 4730 -0.4% 1.00x(?)
ArrayAppendSequence 1062 1061 -0.1% 1.00x(?)
ArrayAppendArrayOfInt 599 599 +0.0% 1.00x
ArrayOfPOD 182 182 +0.0% 1.00x
SetUnion 2436 2442 +0.2% 1.00x(?)
Chars 620 623 +0.5% 1.00x
DeadArray 185 185 +0.0% 1.00x
ArrayValueProp2 6 6 +0.0% 1.00x
BitCount 1 1 +0.0% 1.00x
AnyHashableWithAClass 64311 64153 -0.2% 1.00x(?)
ArrayValueProp3 6 6 +0.0% 1.00x
StringWalk 5898 5912 +0.2% 1.00x(?)
ArrayValueProp 6 6 +0.0% 1.00x
ObjectiveCBridgeFromNSString 1784 1781 -0.2% 1.00x(?)
GlobalClass 0 0 +0.0% 1.00x
Memset 235 235 +0.0% 1.00x
Dictionary2OfObjects 3459 3447 -0.3% 1.00x(?)
ArrayValueProp4 6 6 +0.0% 1.00x
ObjectiveCBridgeStubNSDataAppend 2400 2394 -0.2% 1.00x(?)
DictionarySwapOfObjects 6200 6260 +1.0% 0.99x(?)
DictionaryBridge 3673 3693 +0.5% 0.99x(?)
RangeAssignment 288 290 +0.7% 0.99x(?)
ArrayAppendLazyMap 846 851 +0.6% 0.99x(?)
ObjectiveCBridgeStubFromNSStringRef 135 137 +1.5% 0.99x(?)
ObjectiveCBridgeStubFromNSString 754 759 +0.7% 0.99x(?)
ObjectAllocation 153 154 +0.7% 0.99x(?)
ObjectiveCBridgeFromNSSetAnyObject 84486 85140 +0.8% 0.99x(?)
HashTest 1727 1745 +1.0% 0.99x(?)
Join 469 472 +0.6% 0.99x(?)
ArrayAppendOptionals 1230 1240 +0.8% 0.99x(?)
ObjectiveCBridgeStubToNSDateRef 3440 3462 +0.6% 0.99x(?)
ObjectiveCBridgeStubToArrayOfNSString 29511 29804 +1.0% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObject 75762 76470 +0.9% 0.99x(?)
SetIntersect 351 355 +1.1% 0.99x(?)
RGBHistogram 2223 2252 +1.3% 0.99x(?)
ObserverForwarderStruct 932 941 +1.0% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 90524 91167 +0.7% 0.99x(?)
ObjectiveCBridgeStubFromArrayOfNSString 58317 58794 +0.8% 0.99x(?)
SevenBoom 1346 1354 +0.6% 0.99x(?)
ObserverPartiallyAppliedMethod 3378 3406 +0.8% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToString 118339 120945 +2.2% 0.98x(?)
ArrayAppendGenericStructs 1225 1246 +1.7% 0.98x(?)
Dictionary 719 730 +1.5% 0.98x
Walsh 312 320 +2.6% 0.98x
PopFrontArray 1117 1159 +3.8% 0.96x(?)
Hanoi 3179 3357 +5.6% 0.95x
StringHasSuffix 816 861 +5.5% 0.95x
**Unoptimized (Onone)**
Regression (4)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
SortLettersInPlace 2543 2761 +8.6% 0.92x
ArrayAppend 3352 3554 +6.0% 0.94x
ObjectiveCBridgeStubDateMutation 486 517 +6.4% 0.94x
ArrayAppendReserved 3090 3300 +6.8% 0.94x
Improvement (3)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
SortStrings 2753 2506 -9.0% 1.10x
SortStringsUnicode 9293 8304 -10.6% 1.12x
StaticArray 35323 11375 -67.8% 3.11x
No Changes (140)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
ObjectiveCBridgeStubToNSDate 14485 13942 -3.8% 1.04x(?)
ObjectiveCBridgeFromNSArrayAnyObjectForced 10477 10191 -2.7% 1.03x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 212484 209091 -1.6% 1.02x(?)
NSDictionaryCastToSwift 6284 6189 -1.5% 1.02x(?)
ObjectiveCBridgeFromNSDictionaryAnyObject 184205 182598 -0.9% 1.01x(?)
StrComplexWalk 7658 7619 -0.5% 1.01x(?)
StringInterpolation 15859 15714 -0.9% 1.01x(?)
DictionaryLiteral 15717 15635 -0.5% 1.01x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 134910 133916 -0.7% 1.01x(?)
Dictionary 1860 1849 -0.6% 1.01x
ObjectiveCBridgeToNSSet 40511 40220 -0.7% 1.01x(?)
RGBHistogramOfObjects 89581 88771 -0.9% 1.01x
ArrayAppendSequence 104916 104143 -0.7% 1.01x
ArrayValueProp3 3088 3072 -0.5% 1.01x
ObjectiveCBridgeStubFromArrayOfNSString 59088 58682 -0.7% 1.01x(?)
ArraySubscript 5641 5631 -0.2% 1.00x(?)
ObjectiveCBridgeToNSString 1102 1104 +0.2% 1.00x(?)
DictionarySwapOfObjects 19251 19327 +0.4% 1.00x(?)
PopFrontArray 24145 24235 +0.4% 1.00x(?)
RecursiveOwnedParameter 10914 10927 +0.1% 1.00x(?)
ObjectiveCBridgeStubToNSString 1337 1334 -0.2% 1.00x(?)
ClassArrayGetter 1266 1267 +0.1% 1.00x(?)
Array2D 812123 812172 +0.0% 1.00x(?)
Histogram 10098 10089 -0.1% 1.00x(?)
DictionaryBridge 3764 3768 +0.1% 1.00x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 7925 7941 +0.2% 1.00x(?)
MonteCarloPi 53580 53585 +0.0% 1.00x(?)
StringWithCString 152866 152732 -0.1% 1.00x(?)
ObjectiveCBridgeFromNSStringForced 3107 3113 +0.2% 1.00x(?)
Prims 13240 13210 -0.2% 1.00x(?)
DictionarySwap 6103 6090 -0.2% 1.00x(?)
ObjectiveCBridgeFromNSString 5100 5112 +0.2% 1.00x(?)
ArrayOfGenericPOD 3433 3430 -0.1% 1.00x(?)
Dictionary3OfObjects 2001 1996 -0.2% 1.00x(?)
RangeAssignment 13254 13280 +0.2% 1.00x(?)
ByteSwap 9 9 +0.0% 1.00x
SuperChars 263652 263825 +0.1% 1.00x(?)
ArrayAppendLazyMap 244376 244398 +0.0% 1.00x(?)
XorLoop 19984 20002 +0.1% 1.00x(?)
ObserverClosure 6937 6906 -0.5% 1.00x(?)
Integrate 368 368 +0.0% 1.00x
ArrayAppendStrings 11849 11804 -0.4% 1.00x(?)
ObjectAllocation 551 550 -0.2% 1.00x(?)
ArrayLiteral 1251 1248 -0.2% 1.00x(?)
ProtocolDispatch2 441 442 +0.2% 1.00x(?)
Walsh 13375 13366 -0.1% 1.00x(?)
Dictionary3 1394 1394 +0.0% 1.00x
Dictionary2 4050 4033 -0.4% 1.00x(?)
SetIntersect_OfObjects 11944 11961 +0.1% 1.00x(?)
Join 1462 1461 -0.1% 1.00x(?)
ArrayOfRef 9080 9121 +0.5% 1.00x(?)
ObserverUnappliedMethod 8767 8796 +0.3% 1.00x(?)
ObjectiveCBridgeStubURLAppendPathRef 233940 235019 +0.5% 1.00x(?)
ArrayAppendOptionals 1299 1300 +0.1% 1.00x(?)
NSError 685 686 +0.1% 1.00x(?)
DictionaryOfObjects 4562 4567 +0.1% 1.00x(?)
PopFrontArrayGeneric 9649 9612 -0.4% 1.00x(?)
PopFrontUnsafePointer 258851 258952 +0.0% 1.00x(?)
CaptureProp 118800 119230 +0.4% 1.00x(?)
PolymorphicCalls 1153 1156 +0.3% 1.00x(?)
RC4 9386 9382 -0.0% 1.00x(?)
ObjectiveCBridgeStubToNSStringRef 156 156 +0.0% 1.00x
Calculator 928 929 +0.1% 1.00x(?)
MapReduce 44960 45010 +0.1% 1.00x(?)
AngryPhonebook 3022 3019 -0.1% 1.00x(?)
IterateData 10611 10594 -0.2% 1.00x(?)
Hanoi 19117 19153 +0.2% 1.00x(?)
DictionaryRemoveOfObjects 46524 46465 -0.1% 1.00x(?)
ObjectiveCBridgeStubURLAppendPath 234570 234489 -0.0% 1.00x(?)
SetIsSubsetOf 2128 2133 +0.2% 1.00x(?)
NopDeinit 61205 61159 -0.1% 1.00x(?)
ObjectiveCBridgeStubToArrayOfNSString 29941 29990 +0.2% 1.00x(?)
ObjectiveCBridgeFromNSArrayAnyObject 79244 79075 -0.2% 1.00x(?)
ObjectiveCBridgeStubDataAppend 3576 3565 -0.3% 1.00x(?)
SetExclusiveOr 23783 23694 -0.4% 1.00x
ArrayInClass 3956 3957 +0.0% 1.00x(?)
ArrayOfGenericRef 10023 10014 -0.1% 1.00x(?)
Sim2DArray 14782 14774 -0.1% 1.00x(?)
SetExclusiveOr_OfObjects 40301 40261 -0.1% 1.00x(?)
ObjectiveCBridgeToNSDictionary 63162 63365 +0.3% 1.00x(?)
MonteCarloE 108104 107891 -0.2% 1.00x(?)
SetUnion_OfObjects 28258 28355 +0.3% 1.00x
StringHasSuffixUnicode 64719 64763 +0.1% 1.00x(?)
HashTest 5259 5259 +0.0% 1.00x
SetIsSubsetOf_OfObjects 1913 1910 -0.2% 1.00x(?)
DictionaryRemove 16774 16794 +0.1% 1.00x(?)
StringHasPrefixUnicode 15928 15932 +0.0% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 113074 112858 -0.2% 1.00x(?)
NSStringConversion 3001 3002 +0.0% 1.00x(?)
RGBHistogram 40179 40172 -0.0% 1.00x(?)
ArrayAppendArrayOfInt 639 639 +0.0% 1.00x
ArrayOfPOD 2329 2328 -0.0% 1.00x(?)
SetUnion 12205 12215 +0.1% 1.00x(?)
Chars 5008 4997 -0.2% 1.00x(?)
ObserverForwarderStruct 5280 5265 -0.3% 1.00x(?)
146 5952663 5981340 +0.5% 1.00x
DeadArray 120806 121336 +0.4% 1.00x(?)
ArrayValueProp2 3200 3202 +0.1% 1.00x(?)
BitCount 97 97 +0.0% 1.00x
AnyHashableWithAClass 79241 79488 +0.3% 1.00x(?)
StringWalk 22576 22595 +0.1% 1.00x(?)
ArrayValueProp 2614 2618 +0.1% 1.00x(?)
ObjectiveCBridgeStubNSDateMutationRef 14597 14537 -0.4% 1.00x(?)
GlobalClass 0 0 +0.0% 1.00x
Memset 20966 20963 -0.0% 1.00x(?)
Dictionary2OfObjects 5938 5922 -0.3% 1.00x(?)
ArrayValueProp4 3091 3096 +0.2% 1.00x(?)
TwoSum 4954 4970 +0.3% 1.00x(?)
ObjectiveCBridgeStubNSDataAppend 2779 2792 +0.5% 1.00x(?)
SevenBoom 1492 1496 +0.3% 1.00x(?)
ObserverPartiallyAppliedMethod 8276 8268 -0.1% 1.00x(?)
StackPromo 128013 128951 +0.7% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToString 122060 122698 +0.5% 0.99x(?)
ObjectiveCBridgeStubFromNSDateRef 4014 4043 +0.7% 0.99x
ObjectiveCBridgeStubFromNSString 800 805 +0.6% 0.99x(?)
ProtocolDispatch 6384 6469 +1.3% 0.99x(?)
ObjectiveCBridgeFromNSSetAnyObject 89998 90744 +0.8% 0.99x(?)
ObjectiveCBridgeToNSArray 30920 31135 +0.7% 0.99x(?)
ObjectiveCBridgeStubToNSDateRef 3320 3361 +1.2% 0.99x(?)
StringEqualPointerComparison 9585 9662 +0.8% 0.99x
SetIntersect 13175 13245 +0.5% 0.99x
StringBuilder 2747 2771 +0.9% 0.99x(?)
ArrayAppendRepeatCol 213595 215149 +0.7% 0.99x(?)
LinkedList 27659 27852 +0.7% 0.99x(?)
ObjectiveCBridgeFromNSSetAnyObjectForced 7550 7592 +0.6% 0.99x(?)
StrToInt 5732 5810 +1.4% 0.99x
ObjectiveCBridgeStubFromNSDate 3716 3746 +0.8% 0.99x(?)
ArrayAppendGenericStructs 1298 1318 +1.5% 0.98x(?)
ErrorHandling 3757 3827 +1.9% 0.98x(?)
ObjectiveCBridgeStubFromNSStringRef 161 164 +1.9% 0.98x(?)
StringHasPrefix 1587 1627 +2.5% 0.98x
UTF8Decode 43584 44295 +1.6% 0.98x(?)
ObjectiveCBridgeStubNSDateRefAccess 1228 1259 +2.5% 0.98x
StringHasSuffix 1560 1584 +1.5% 0.98x
Phonebook 61803 62819 +1.6% 0.98x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 92645 94976 +2.5% 0.98x(?)
OpenClose 445 460 +3.4% 0.97x
ObjectiveCBridgeStubDateAccess 1064 1097 +3.1% 0.97x
TypeFlood 195 204 +4.6% 0.96x(?)
ObjectiveCBridgeFromNSSetAnyObjectToString 152261 158505 +4.1% 0.96x(?)
**Hardware Overview** Model Name: Mac mini Model Identifier: Macmini7,1 Processor Name: Intel Core i5 Processor Speed: 2.8 GHz Number of Processors: 1 Total Number of Cores: 2 L2 Cache (per Core): 256 KB L3 Cache: 3 MB Memory: 16 GB

@natecook1000
Copy link
Member Author

@gottesmm Will do! I don't think it wasn't intended to test sorting performance, but the StaticArray test includes a sort of a reverse ordered "array", so you can see the performance increase there: ~3x unoptimized and ~5.5x optimized.

@swift-ci
Copy link
Contributor

Build comment file:

Optimized (O)

Regression (6)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
ObjectiveCBridgeStubDateAccess 182 212 +16.5% 0.86x
StringHasPrefix 669 753 +12.6% 0.89x
PopFrontArrayGeneric 1119 1256 +12.2% 0.89x(?)
StringHasSuffix 746 831 +11.4% 0.90x
MapReduce 342 372 +8.8% 0.92x
SortLettersInPlace 977 1041 +6.5% 0.94x
Improvement (7)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
OpenClose 54 51 -5.6% 1.06x
Phonebook 7602 7145 -6.0% 1.06x
SortStrings 1825 1655 -9.3% 1.10x
Calculator 34 30 -11.8% 1.13x
SortStringsUnicode 8266 7170 -13.3% 1.15x
StringWithCString 198572 155094 -21.9% 1.28x(?)
StaticArray 2711 480 -82.3% 5.65x
No Changes (138)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
Walsh 325 309 -4.9% 1.05x
Hanoi 3347 3195 -4.5% 1.05x
StrToInt 5249 5017 -4.4% 1.05x
ObjectiveCBridgeStubNSDateMutationRef 12613 12173 -3.5% 1.04x(?)
PopFrontArray 1118 1084 -3.0% 1.03x(?)
StringInterpolation 11074 10899 -1.6% 1.02x(?)
StringEqualPointerComparison 7429 7297 -1.8% 1.02x(?)
SetIntersect 360 352 -2.2% 1.02x(?)
RecursiveOwnedParameter 1945 1935 -0.5% 1.01x
Array2D 2031 2018 -0.6% 1.01x(?)
ObjectiveCBridgeFromNSArrayAnyObjectForced 6291 6257 -0.5% 1.01x(?)
Prims 736 732 -0.5% 1.01x(?)
RangeAssignment 290 288 -0.7% 1.01x(?)
ObjectiveCBridgeStubToNSString 1283 1275 -0.6% 1.01x(?)
ProtocolDispatch2 160 159 -0.6% 1.01x
Dictionary2 2052 2031 -1.0% 1.01x(?)
StrComplexWalk 2910 2884 -0.9% 1.01x(?)
ArrayOfRef 3559 3537 -0.6% 1.01x(?)
ObjectiveCBridgeStubToNSDateRef 3780 3735 -1.2% 1.01x(?)
ObjectiveCBridgeStubURLAppendPath 236142 234564 -0.7% 1.01x(?)
SetExclusiveOr 2906 2875 -1.1% 1.01x(?)
ArrayOfGenericRef 3612 3570 -1.2% 1.01x(?)
HashTest 1748 1731 -1.0% 1.01x(?)
StringHasPrefixUnicode 14429 14224 -1.4% 1.01x
ObjectiveCBridgeFromNSSetAnyObjectToString 139279 137639 -1.2% 1.01x(?)
NSStringConversion 808 799 -1.1% 1.01x(?)
SetUnion 2440 2422 -0.7% 1.01x(?)
Chars 630 623 -1.1% 1.01x
ObjectiveCBridgeStubNSDataAppend 2442 2410 -1.3% 1.01x(?)
TwoSum 1328 1319 -0.7% 1.01x(?)
ObjectiveCBridgeToNSString 1077 1074 -0.3% 1.00x(?)
DictionarySwapOfObjects 6264 6244 -0.3% 1.00x(?)
StackPromo 21525 21554 +0.1% 1.00x(?)
Integrate 238 238 +0.0% 1.00x
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 203858 203515 -0.2% 1.00x(?)
ClassArrayGetter 12 12 +0.0% 1.00x
DictionaryBridge 3681 3685 +0.1% 1.00x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 5488 5497 +0.2% 1.00x(?)
ObjectiveCBridgeStubFromNSDateRef 3883 3891 +0.2% 1.00x(?)
MonteCarloPi 44997 45002 +0.0% 1.00x(?)
DictionarySwap 412 414 +0.5% 1.00x
ArrayAppendToFromGeneric 1073 1074 +0.1% 1.00x(?)
Dictionary3OfObjects 873 872 -0.1% 1.00x(?)
ByteSwap 0 0 +0.0% 1.00x
ArrayAppendGenericStructs 1248 1244 -0.3% 1.00x(?)
SuperChars 212475 211569 -0.4% 1.00x(?)
ArrayAppendLazyMap 843 840 -0.4% 1.00x(?)
XorLoop 380 380 +0.0% 1.00x
ArrayAppendReserved 537 536 -0.2% 1.00x(?)
ArrayAppendStrings 12112 12120 +0.1% 1.00x(?)
Join 463 464 +0.2% 1.00x(?)
ObjectiveCBridgeStubFromNSStringRef 135 135 +0.0% 1.00x
ObjectiveCBridgeStubFromNSString 758 758 +0.0% 1.00x
ProtocolDispatch 3038 3040 +0.1% 1.00x(?)
ObjectAllocation 153 153 +0.0% 1.00x
TypeFlood 0 0 +0.0% 1.00x
ObjectiveCBridgeFromNSSetAnyObject 84980 84899 -0.1% 1.00x(?)
ArrayLiteral 1180 1182 +0.2% 1.00x(?)
Dictionary3 519 519 +0.0% 1.00x
SetIntersect_OfObjects 1503 1503 +0.0% 1.00x
ErrorHandling 2919 2918 -0.0% 1.00x(?)
ObjectiveCBridgeStubURLAppendPathRef 236023 235647 -0.2% 1.00x(?)
ArrayAppend 775 775 +0.0% 1.00x
ArrayPlusEqualArrayOfInt 600 600 +0.0% 1.00x
NSError 323 324 +0.3% 1.00x(?)
DictionaryOfObjects 2288 2298 +0.4% 1.00x(?)
CaptureProp 4565 4563 -0.0% 1.00x(?)
RC4 165 165 +0.0% 1.00x
ObjectiveCBridgeStubToNSStringRef 124 124 +0.0% 1.00x
ArrayAppendFromGeneric 1072 1075 +0.3% 1.00x(?)
ObjectiveCBridgeStubDateMutation 273 273 +0.0% 1.00x
AngryPhonebook 2825 2836 +0.4% 1.00x(?)
IterateData 2619 2606 -0.5% 1.00x
DictionaryLiteral 1265 1268 +0.2% 1.00x(?)
ArrayOfGenericPOD 220 220 +0.0% 1.00x
DictionaryRemoveOfObjects 19327 19403 +0.4% 1.00x(?)
UTF8Decode 288 288 +0.0% 1.00x
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 130321 130209 -0.1% 1.00x(?)
SetIsSubsetOf 250 250 +0.0% 1.00x
Dictionary 718 715 -0.4% 1.00x(?)
NopDeinit 36673 36660 -0.0% 1.00x(?)
ObjectiveCBridgeStubToArrayOfNSString 29941 29859 -0.3% 1.00x(?)
ObjectiveCBridgeFromNSArrayAnyObject 75774 76145 +0.5% 1.00x(?)
ObjectiveCBridgeStubDataAppend 3348 3351 +0.1% 1.00x(?)
NSDictionaryCastToSwift 4990 4971 -0.4% 1.00x(?)
RGBHistogramOfObjects 21521 21461 -0.3% 1.00x(?)
ObjectiveCBridgeStubNSDateRefAccess 308 308 +0.0% 1.00x
StringBuilder 1312 1312 +0.0% 1.00x
ArrayInClass 62 62 +0.0% 1.00x
ObjectiveCBridgeFromNSString 1796 1801 +0.3% 1.00x(?)
Sim2DArray 277 277 +0.0% 1.00x
SetExclusiveOr_OfObjects 7451 7428 -0.3% 1.00x(?)
ArrayAppendRepeatCol 643 644 +0.2% 1.00x(?)
MonteCarloE 10470 10438 -0.3% 1.00x(?)
SetUnion_OfObjects 6257 6237 -0.3% 1.00x(?)
StringHasSuffixUnicode 63504 63308 -0.3% 1.00x(?)
ArrayAppendToGeneric 1073 1073 +0.0% 1.00x
SetIsSubsetOf_OfObjects 307 307 +0.0% 1.00x
ObjectiveCBridgeToNSSet 39735 39724 -0.0% 1.00x(?)
LinkedList 7254 7258 +0.1% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 102551 102046 -0.5% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectForced 4748 4753 +0.1% 1.00x(?)
ArrayAppendSequence 1062 1062 +0.0% 1.00x
ArrayAppendArrayOfInt 600 599 -0.2% 1.00x(?)
ArrayOfPOD 182 182 +0.0% 1.00x
DeadArray 184 184 +0.0% 1.00x
BitCount 1 1 +0.0% 1.00x
AnyHashableWithAClass 63867 63592 -0.4% 1.00x(?)
SevenBoom 1351 1347 -0.3% 1.00x(?)
StringWalk 5898 5896 -0.0% 1.00x(?)
ArrayValueProp 6 6 +0.0% 1.00x
GlobalClass 0 0 +0.0% 1.00x
Memset 235 235 +0.0% 1.00x
Dictionary2OfObjects 3447 3433 -0.4% 1.00x(?)
ArrayValueProp4 6 6 +0.0% 1.00x
ArrayValueProp2 6 6 +0.0% 1.00x
ArrayValueProp3 6 6 +0.0% 1.00x
ObserverPartiallyAppliedMethod 3338 3336 -0.1% 1.00x(?)
ArraySubscript 1424 1435 +0.8% 0.99x(?)
ObjectiveCBridgeFromNSDictionaryAnyObject 176912 178682 +1.0% 0.99x(?)
Histogram 287 289 +0.7% 0.99x(?)
ObjectiveCBridgeFromNSStringForced 2658 2690 +1.2% 0.99x(?)
ObjectiveCBridgeStubToNSDate 13769 13937 +1.2% 0.99x(?)
ObserverClosure 1953 1967 +0.7% 0.99x(?)
ObjectiveCBridgeToNSArray 30236 30653 +1.4% 0.99x(?)
PopFrontUnsafePointer 9117 9176 +0.7% 0.99x(?)
ArrayAppendOptionals 1234 1244 +0.8% 0.99x(?)
DictionaryRemove 2301 2318 +0.7% 0.99x(?)
RGBHistogram 2220 2253 +1.5% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 89598 90870 +1.4% 0.99x(?)
ObjectiveCBridgeStubFromArrayOfNSString 58396 58716 +0.6% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToString 116865 119640 +2.4% 0.98x(?)
ObserverUnappliedMethod 2371 2408 +1.6% 0.98x(?)
ObjectiveCBridgeToNSDictionary 62430 63564 +1.8% 0.98x(?)
150 3124853 3181135 +1.8% 0.98x
ObserverForwarderStruct 888 903 +1.7% 0.98x(?)
ObjectiveCBridgeStubFromNSDate 3689 3805 +3.1% 0.97x(?)
PolymorphicCalls 21 22 +4.8% 0.95x
**Unoptimized (Onone)**
Regression (5)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
ArrayAppendReserved 3092 3629 +17.4% 0.85x
SortLettersInPlace 2537 2755 +8.6% 0.92x
ObjectiveCBridgeStubToNSDate 13528 14331 +5.9% 0.94x(?)
ArrayAppend 3351 3552 +6.0% 0.94x
ObjectiveCBridgeStubDateMutation 486 517 +6.4% 0.94x
Improvement (4)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
TypeFlood 213 199 -6.6% 1.07x(?)
SortStrings 2721 2491 -8.4% 1.09x
SortStringsUnicode 9388 8366 -10.9% 1.12x
StaticArray 35336 11368 -67.8% 3.11x
No Changes (142)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
ProtocolDispatch 6406 6082 -5.1% 1.05x
ObjectiveCBridgeFromNSArrayAnyObjectForced 10964 10500 -4.2% 1.04x(?)
ObjectiveCBridgeFromNSSetAnyObjectToString 161244 156056 -3.2% 1.03x(?)
Chars 5216 5058 -3.0% 1.03x
ArrayAppendOptionals 1341 1311 -2.2% 1.02x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 138444 135256 -2.3% 1.02x(?)
Phonebook 63227 62235 -1.6% 1.02x(?)
ObjectiveCBridgeFromNSSetAnyObjectForced 7924 7738 -2.4% 1.02x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 217485 215179 -1.1% 1.01x(?)
Dictionary3OfObjects 2010 1999 -0.6% 1.01x(?)
ArrayAppendGenericStructs 1305 1295 -0.8% 1.01x(?)
StringHasSuffix 1633 1615 -1.1% 1.01x
ObjectAllocation 563 555 -1.4% 1.01x(?)
ObjectiveCBridgeToNSArray 30995 30728 -0.9% 1.01x(?)
IterateData 10661 10594 -0.6% 1.01x
ObjectiveCBridgeStubToArrayOfNSString 30135 29851 -0.9% 1.01x(?)
RGBHistogramOfObjects 89685 88857 -0.9% 1.01x
StringHasPrefixUnicode 15827 15746 -0.5% 1.01x
NSStringConversion 2994 2972 -0.7% 1.01x(?)
ArrayAppendSequence 104884 104088 -0.8% 1.01x(?)
ArraySubscript 5628 5639 +0.2% 1.00x
ObjectiveCBridgeToNSString 1106 1110 +0.4% 1.00x(?)
DictionarySwapOfObjects 19264 19170 -0.5% 1.00x(?)
ObjectiveCBridgeFromNSDictionaryAnyObject 184445 185243 +0.4% 1.00x(?)
RecursiveOwnedParameter 10913 10908 -0.1% 1.00x(?)
Integrate 368 368 +0.0% 1.00x
ClassArrayGetter 1267 1266 -0.1% 1.00x(?)
Array2D 812064 812333 +0.0% 1.00x(?)
Histogram 10134 10124 -0.1% 1.00x(?)
ArrayOfGenericPOD 3430 3427 -0.1% 1.00x(?)
StringWithCString 152698 152757 +0.0% 1.00x(?)
ObjectiveCBridgeFromNSStringForced 3105 3111 +0.2% 1.00x(?)
Prims 13129 13144 +0.1% 1.00x(?)
DictionarySwap 6085 6083 -0.0% 1.00x(?)
ArrayAppendToFromGeneric 219520 218916 -0.3% 1.00x(?)
PopFrontArray 24299 24257 -0.2% 1.00x(?)
RangeAssignment 13264 13272 +0.1% 1.00x(?)
StrComplexWalk 7874 7859 -0.2% 1.00x(?)
ByteSwap 9 9 +0.0% 1.00x
SuperChars 264117 263727 -0.1% 1.00x(?)
ArrayAppendLazyMap 244711 244292 -0.2% 1.00x(?)
XorLoop 19997 19996 -0.0% 1.00x(?)
StringInterpolation 15782 15722 -0.4% 1.00x(?)
ObserverClosure 6887 6893 +0.1% 1.00x(?)
ObjectiveCBridgeStubToNSString 1335 1334 -0.1% 1.00x(?)
ArrayAppendStrings 11824 11806 -0.1% 1.00x(?)
ErrorHandling 3824 3819 -0.1% 1.00x(?)
ObjectiveCBridgeStubFromNSString 798 802 +0.5% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObject 91362 91209 -0.2% 1.00x(?)
ArrayLiteral 1248 1250 +0.2% 1.00x(?)
ProtocolDispatch2 459 459 +0.0% 1.00x
Walsh 13355 13341 -0.1% 1.00x(?)
Dictionary3 1387 1393 +0.4% 1.00x(?)
Dictionary2 4035 4039 +0.1% 1.00x(?)
SetIntersect_OfObjects 11907 11926 +0.2% 1.00x(?)
Join 1458 1457 -0.1% 1.00x(?)
ArrayOfRef 9115 9121 +0.1% 1.00x(?)
ObserverUnappliedMethod 8661 8700 +0.5% 1.00x(?)
ObjectiveCBridgeStubURLAppendPathRef 238591 238188 -0.2% 1.00x(?)
ArrayPlusEqualArrayOfInt 642 642 +0.0% 1.00x
NSError 676 679 +0.4% 1.00x(?)
DictionaryOfObjects 4561 4563 +0.0% 1.00x(?)
ObjectiveCBridgeStubToNSDateRef 3395 3398 +0.1% 1.00x(?)
PopFrontArrayGeneric 9550 9554 +0.0% 1.00x(?)
PopFrontUnsafePointer 259410 258962 -0.2% 1.00x(?)
StringEqualPointerComparison 9660 9703 +0.5% 1.00x
PolymorphicCalls 1157 1160 +0.3% 1.00x(?)
RC4 9388 9381 -0.1% 1.00x(?)
ObjectiveCBridgeStubToNSStringRef 156 156 +0.0% 1.00x
Calculator 1002 1002 +0.0% 1.00x
ArrayAppendFromGeneric 219315 219093 -0.1% 1.00x(?)
MapReduce 44987 45053 +0.1% 1.00x
AngryPhonebook 2995 2995 +0.0% 1.00x
DictionaryLiteral 15728 15720 -0.1% 1.00x(?)
Hanoi 19211 19182 -0.1% 1.00x(?)
DictionaryRemoveOfObjects 46457 46521 +0.1% 1.00x(?)
UTF8Decode 43713 43782 +0.2% 1.00x(?)
ObjectiveCBridgeStubURLAppendPath 238194 237452 -0.3% 1.00x(?)
SetIsSubsetOf 2133 2136 +0.1% 1.00x(?)
Dictionary 1857 1850 -0.4% 1.00x(?)
NopDeinit 61217 61181 -0.1% 1.00x(?)
ObjectiveCBridgeFromNSArrayAnyObject 78817 79103 +0.4% 1.00x(?)
SetIntersect 13175 13231 +0.4% 1.00x(?)
ObjectiveCBridgeStubDataAppend 3528 3525 -0.1% 1.00x(?)
SetExclusiveOr 23872 23766 -0.4% 1.00x(?)
NSDictionaryCastToSwift 6193 6206 +0.2% 1.00x(?)
ArrayInClass 3957 3955 -0.1% 1.00x(?)
ArrayOfGenericRef 10041 10043 +0.0% 1.00x(?)
ObjectiveCBridgeFromNSString 5115 5099 -0.3% 1.00x(?)
Sim2DArray 14779 14768 -0.1% 1.00x(?)
MonteCarloPi 53571 53611 +0.1% 1.00x(?)
MonteCarloE 107972 107969 -0.0% 1.00x(?)
SetUnion_OfObjects 28216 28319 +0.4% 1.00x(?)
StringHasSuffixUnicode 64826 64830 +0.0% 1.00x(?)
ArrayAppendToGeneric 219484 218946 -0.2% 1.00x(?)
HashTest 5255 5261 +0.1% 1.00x(?)
SetIsSubsetOf_OfObjects 1896 1893 -0.2% 1.00x(?)
ObjectiveCBridgeToNSSet 40415 40563 +0.4% 1.00x(?)
DictionaryRemove 16761 16748 -0.1% 1.00x(?)
150 6661861 6629218 -0.5% 1.00x
LinkedList 27892 27877 -0.1% 1.00x(?)
RGBHistogram 40175 40177 +0.0% 1.00x(?)
ArrayAppendArrayOfInt 640 640 +0.0% 1.00x
ArrayOfPOD 2327 2330 +0.1% 1.00x(?)
SetUnion 12240 12277 +0.3% 1.00x(?)
StrToInt 5766 5770 +0.1% 1.00x(?)
ObserverForwarderStruct 5216 5226 +0.2% 1.00x(?)
ArrayValueProp2 3145 3158 +0.4% 1.00x
AnyHashableWithAClass 79217 79450 +0.3% 1.00x(?)
SevenBoom 1508 1512 +0.3% 1.00x(?)
StringWalk 23557 23633 +0.3% 1.00x
ArrayValueProp 2636 2641 +0.2% 1.00x(?)
GlobalClass 0 0 +0.0% 1.00x
Memset 20968 20970 +0.0% 1.00x(?)
Dictionary2OfObjects 5908 5919 +0.2% 1.00x(?)
ArrayValueProp4 3017 3021 +0.1% 1.00x(?)
TwoSum 4960 4959 -0.0% 1.00x(?)
ArrayValueProp3 3071 3073 +0.1% 1.00x(?)
ObserverPartiallyAppliedMethod 8207 8227 +0.2% 1.00x(?)
StackPromo 126160 127247 +0.9% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToString 123702 124363 +0.5% 0.99x(?)
DictionaryBridge 3745 3798 +1.4% 0.99x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 7868 7987 +1.5% 0.99x(?)
ObjectiveCBridgeStubFromNSDateRef 4079 4112 +0.8% 0.99x
ObjectiveCBridgeStubFromNSStringRef 160 161 +0.6% 0.99x(?)
CaptureProp 118285 118885 +0.5% 0.99x
OpenClose 446 449 +0.7% 0.99x(?)
StringBuilder 2714 2737 +0.8% 0.99x(?)
SetExclusiveOr_OfObjects 40270 40509 +0.6% 0.99x
ArrayAppendRepeatCol 213517 215017 +0.7% 0.99x(?)
DeadArray 119878 120830 +0.8% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 93320 94308 +1.1% 0.99x(?)
ObjectiveCBridgeStubFromArrayOfNSString 58657 59004 +0.6% 0.99x(?)
ObjectiveCBridgeStubFromNSDate 3791 3825 +0.9% 0.99x
StringHasPrefix 1612 1643 +1.9% 0.98x
ObjectiveCBridgeToNSDictionary 62720 63975 +2.0% 0.98x(?)
ObjectiveCBridgeStubNSDataAppend 2767 2810 +1.6% 0.98x(?)
ObjectiveCBridgeStubNSDateRefAccess 1226 1262 +2.9% 0.97x
BitCount 100 103 +3.0% 0.97x
ObjectiveCBridgeStubNSDateMutationRef 14308 14746 +3.1% 0.97x(?)
ObjectiveCBridgeStubDateAccess 1095 1141 +4.2% 0.96x
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 113577 118085 +4.0% 0.96x(?)
**Hardware Overview** Model Name: Mac mini Model Identifier: Macmini7,1 Processor Name: Intel Core i5 Processor Speed: 2.8 GHz Number of Processors: 1 Total Number of Cores: 2 L2 Cache (per Core): 256 KB L3 Cache: 3 MB Memory: 16 GB

@natecook1000
Copy link
Member Author

@gottesmm Test added—definitely shows a difference!

(master):swift-macosx-x86_64$ /bin/Benchmark_O SortSortedStrings --num-iters=50 --num-samples=10
#,TEST,SAMPLES,MIN(us),MAX(us),MEAN(us),SD(us),MEDIAN(us)
126,SortSortedStrings,10,4557,4926,4708,96,4716

(nc-sort-median):swift-macosx-x86_64$ /bin/Benchmark_O SortSortedStrings --num-iters=50 --num-samples=10
#,TEST,SAMPLES,MIN(us),MAX(us),MEAN(us),SD(us),MEDIAN(us)
126,SortSortedStrings,20,776,909,809,45,788

@natecook1000
Copy link
Member Author

@swift-ci Please benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Optimized (O)


This modifies the _partition function used during sorting to select
the median of the first, middle, and last elements in the range to
be partitioned. Before partitioning begins, those three elements are
sorted, after which the middle element is selected as the pivot. This
change improves performance for sorted or nearly-sorted data.
@natecook1000
Copy link
Member Author

@swift-ci Please smoke test

@natecook1000
Copy link
Member Author

@swift-ci Please benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Optimized (O)


@gottesmm
Copy link
Contributor

@natecook1000 Thanks for the benchmark!

@natecook1000
Copy link
Member Author

@gottesmm No problem! Seems like the new benchmark is tripping up swift-ci, though. Should I merge that through a separate PR and try again, or do you think we're okay with the performance now?

@natecook1000
Copy link
Member Author

@swift-ci Please benchmark

@swift-ci
Copy link
Contributor

swift-ci commented Jan 4, 2017

Build comment file:

Optimized (O)

Regression (5)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
PopFrontArray 1093 1188 +8.7% 0.92x
SortLettersInPlace 917 981 +7.0% 0.93x
CaptureProp 4038 4309 +6.7% 0.94x
Calculator 30 32 +6.7% 0.94x
Phonebook 6716 7127 +6.1% 0.94x
Improvement (8)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
OpenClose 51 48 -5.9% 1.06x
PopFrontUnsafePointer 9316 8608 -7.6% 1.08x
ObjectiveCBridgeStubNSDateRefAccess 320 296 -7.5% 1.08x
SortStringsUnicode 7736 6934 -10.4% 1.12x
StringHasPrefix 690 603 -12.6% 1.14x
ObjectiveCBridgeStubDateAccess 201 172 -14.4% 1.17x
SortSortedStrings 4217 807 -80.9% 5.23x
StaticArray 681 120 -82.4% 5.67x
No Changes (139)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
NopDeinit 21228 20234 -4.7% 1.05x
ObjectiveCBridgeStubFromNSDate 3608 3523 -2.4% 1.02x
ObjectiveCBridgeFromNSDictionaryAnyObject 157155 156372 -0.5% 1.01x(?)
SortStrings 1626 1606 -1.2% 1.01x
ObjectiveCBridgeFromNSArrayAnyObjectForced 5820 5769 -0.9% 1.01x(?)
Prims 688 684 -0.6% 1.01x(?)
ObjectiveCBridgeFromNSString 1722 1701 -1.2% 1.01x(?)
ObjectiveCBridgeStubToNSDate 12703 12603 -0.8% 1.01x(?)
StringHasSuffixUnicode 59763 59406 -0.6% 1.01x
ObjectiveCBridgeStubURLAppendPath 219465 218353 -0.5% 1.01x(?)
SetUnion_OfObjects 5842 5797 -0.8% 1.01x(?)
NSStringConversion 770 765 -0.7% 1.01x(?)
Chars 602 594 -1.3% 1.01x
ObjectiveCBridgeStubNSDataAppend 2292 2264 -1.2% 1.01x(?)
TwoSum 1242 1231 -0.9% 1.01x(?)
ArraySubscript 1356 1358 +0.1% 1.00x(?)
ObjectiveCBridgeToNSString 1010 1014 +0.4% 1.00x(?)
StackPromo 20325 20240 -0.4% 1.00x(?)
RecursiveOwnedParameter 1826 1835 +0.5% 1.00x
Integrate 225 225 +0.0% 1.00x
ClassArrayGetter 12 12 +0.0% 1.00x
DictionaryBridge 3197 3190 -0.2% 1.00x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 5149 5167 +0.3% 1.00x(?)
ObjectiveCBridgeStubFromNSDateRef 3624 3625 +0.0% 1.00x(?)
MonteCarloPi 42494 42463 -0.1% 1.00x(?)
ObjectiveCBridgeFromNSStringForced 2547 2540 -0.3% 1.00x(?)
ArrayAppendToFromGeneric 1012 1012 +0.0% 1.00x
Dictionary3OfObjects 824 824 +0.0% 1.00x
RangeAssignment 263 264 +0.4% 1.00x(?)
ByteSwap 0 0 +0.0% 1.00x
ArrayAppendGenericStructs 1142 1142 +0.0% 1.00x
SuperChars 199626 199960 +0.2% 1.00x(?)
ArrayAppendLazyMap 794 794 +0.0% 1.00x
XorLoop 359 359 +0.0% 1.00x
StringInterpolation 10395 10415 +0.2% 1.00x(?)
ObserverClosure 1829 1832 +0.2% 1.00x(?)
ObjectiveCBridgeStubToNSString 1213 1210 -0.2% 1.00x(?)
ArrayAppendStrings 11382 11382 +0.0% 1.00x
ErrorHandling 2752 2749 -0.1% 1.00x(?)
ObjectiveCBridgeStubFromNSStringRef 127 127 +0.0% 1.00x
ProtocolDispatch 2870 2871 +0.0% 1.00x(?)
TypeFlood 0 0 +0.0% 1.00x
ObjectiveCBridgeFromNSSetAnyObject 76506 76210 -0.4% 1.00x(?)
ArrayLiteral 1113 1114 +0.1% 1.00x(?)
ProtocolDispatch2 150 150 +0.0% 1.00x
Dictionary3 493 492 -0.2% 1.00x(?)
Dictionary2 1901 1905 +0.2% 1.00x(?)
SetIntersect_OfObjects 1411 1414 +0.2% 1.00x(?)
Join 434 433 -0.2% 1.00x(?)
ArrayOfRef 3303 3311 +0.2% 1.00x(?)
ObserverUnappliedMethod 2167 2168 +0.1% 1.00x(?)
ObjectiveCBridgeToNSSet 35805 35707 -0.3% 1.00x(?)
ArrayPlusEqualArrayOfInt 565 566 +0.2% 1.00x(?)
NSError 307 307 +0.0% 1.00x
DictionaryOfObjects 2155 2153 -0.1% 1.00x(?)
ObjectiveCBridgeStubToNSDateRef 3117 3102 -0.5% 1.00x(?)
PopFrontArrayGeneric 1185 1183 -0.2% 1.00x(?)
StringEqualPointerComparison 6949 6954 +0.1% 1.00x(?)
PolymorphicCalls 20 20 +0.0% 1.00x
ArrayAppendReserved 506 506 +0.0% 1.00x
ObjectiveCBridgeStubToNSStringRef 117 117 +0.0% 1.00x
ArrayAppendFromGeneric 1011 1012 +0.1% 1.00x(?)
MapReduce 322 322 +0.0% 1.00x
ObjectiveCBridgeStubDateMutation 258 258 +0.0% 1.00x
AngryPhonebook 2654 2644 -0.4% 1.00x(?)
IterateData 2473 2476 +0.1% 1.00x(?)
DictionaryLiteral 1194 1193 -0.1% 1.00x(?)
ArrayOfGenericPOD 207 207 +0.0% 1.00x
DictionaryRemoveOfObjects 18346 18390 +0.2% 1.00x(?)
UTF8Decode 272 272 +0.0% 1.00x
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 102399 102121 -0.3% 1.00x(?)
SetIsSubsetOf 236 236 +0.0% 1.00x
ObjectiveCBridgeFromNSArrayAnyObject 69089 69431 +0.5% 1.00x(?)
ObjectiveCBridgeStubDataAppend 3221 3222 +0.0% 1.00x(?)
SetExclusiveOr 2400 2402 +0.1% 1.00x(?)
NSDictionaryCastToSwift 4681 4698 +0.4% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectToString 110037 109772 -0.2% 1.00x(?)
ArrayAppendOptionals 1142 1142 +0.0% 1.00x
ArrayInClass 59 59 +0.0% 1.00x
ArrayOfGenericRef 3362 3363 +0.0% 1.00x(?)
Sim2DArray 261 261 +0.0% 1.00x
SetExclusiveOr_OfObjects 6978 6993 +0.2% 1.00x(?)
ArrayAppendRepeatCol 607 607 +0.0% 1.00x
ObjectiveCBridgeToNSDictionary 57843 58092 +0.4% 1.00x(?)
RC4 156 156 +0.0% 1.00x
ArrayAppendToGeneric 1012 1012 +0.0% 1.00x
HashTest 1646 1647 +0.1% 1.00x(?)
SetIsSubsetOf_OfObjects 289 289 +0.0% 1.00x
ArrayAppend 731 731 +0.0% 1.00x
151 2647311 2658292 +0.4% 1.00x
LinkedList 6843 6852 +0.1% 1.00x(?)
RGBHistogramOfObjects 20239 20221 -0.1% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectForced 4480 4499 +0.4% 1.00x(?)
ArrayAppendSequence 1002 1002 +0.0% 1.00x
ArrayAppendArrayOfInt 565 567 +0.3% 1.00x(?)
ArrayOfPOD 171 171 +0.0% 1.00x
SetUnion 2273 2278 +0.2% 1.00x(?)
StringBuilder 1240 1242 +0.2% 1.00x(?)
ObserverForwarderStruct 844 843 -0.1% 1.00x(?)
BitCount 1 1 +0.0% 1.00x
SevenBoom 1282 1283 +0.1% 1.00x(?)
StringWalk 5549 5550 +0.0% 1.00x(?)
ArrayValueProp 5 5 +0.0% 1.00x
ObjectiveCBridgeStubNSDateMutationRef 11540 11506 -0.3% 1.00x(?)
GlobalClass 0 0 +0.0% 1.00x
Memset 222 222 +0.0% 1.00x
ArrayValueProp4 5 5 +0.0% 1.00x
ArrayValueProp2 5 5 +0.0% 1.00x
ArrayValueProp3 5 5 +0.0% 1.00x
ObserverPartiallyAppliedMethod 3174 3169 -0.2% 1.00x(?)
DictionarySwapOfObjects 5906 5949 +0.7% 0.99x(?)
Array2D 1931 1949 +0.9% 0.99x(?)
Histogram 267 271 +1.5% 0.99x(?)
StringWithCString 146320 147152 +0.6% 0.99x(?)
DictionarySwap 390 392 +0.5% 0.99x(?)
ObjectAllocation 144 145 +0.7% 0.99x(?)
Walsh 304 306 +0.7% 0.99x
StrComplexWalk 2711 2740 +1.1% 0.99x(?)
ObjectiveCBridgeStubURLAppendPathRef 216731 217942 +0.6% 0.99x(?)
ObjectiveCBridgeToNSArray 28600 28871 +0.9% 0.99x(?)
Dictionary 681 689 +1.2% 0.99x(?)
SetIntersect 335 339 +1.2% 0.99x(?)
StringHasSuffix 755 759 +0.5% 0.99x
MonteCarloE 9918 9976 +0.6% 0.99x(?)
DictionaryRemove 2176 2189 +0.6% 0.99x(?)
StringHasPrefixUnicode 12789 12890 +0.8% 0.99x
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 76595 77042 +0.6% 0.99x(?)
DeadArray 172 174 +1.2% 0.99x
AnyHashableWithAClass 62529 62985 +0.7% 0.99x(?)
Dictionary2OfObjects 3217 3235 +0.6% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToString 90076 92123 +2.3% 0.98x(?)
Hanoi 3107 3158 +1.6% 0.98x(?)
ObjectiveCBridgeStubToArrayOfNSString 27564 28027 +1.7% 0.98x(?)
StrToInt 4838 4917 +1.6% 0.98x
RGBHistogram 2122 2159 +1.7% 0.98x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 84366 85813 +1.7% 0.98x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 162165 167600 +3.4% 0.97x(?)
ObjectiveCBridgeStubFromNSString 758 778 +2.6% 0.97x(?)
ObjectiveCBridgeStubFromArrayOfNSString 54148 55940 +3.3% 0.97x(?)
**Unoptimized (Onone)**
Regression (4)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
ProtocolDispatch 5170 5918 +14.5% 0.87x
TypeFlood 184 212 +15.2% 0.87x(?)
SortLettersInPlace 2327 2536 +9.0% 0.92x
StrComplexWalk 7210 7667 +6.3% 0.94x
Improvement (7)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
SortStrings 2612 2469 -5.5% 1.06x
ArrayOfGenericPOD 3061 2897 -5.4% 1.06x
ObjectiveCBridgeStubFromNSStringRef 159 150 -5.7% 1.06x
SortStringsUnicode 8827 7905 -10.4% 1.12x
ObjectiveCBridgeStubDateMutation 488 430 -11.9% 1.13x
StaticArray 10845 3491 -67.8% 3.11x
SortSortedStrings 8208 1214 -85.2% 6.76x
No Changes (141)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
Calculator 948 915 -3.5% 1.04x
OpenClose 384 374 -2.6% 1.03x(?)
ObjectiveCBridgeStubDateAccess 1035 1005 -2.9% 1.03x
Chars 6284 6103 -2.9% 1.03x
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 7668 7548 -1.6% 1.02x(?)
AnyHashableWithAClass 76655 75468 -1.6% 1.02x
NSError 650 638 -1.9% 1.02x(?)
ArrayAppendSequence 90142 88033 -2.3% 1.02x
DictionarySwap 5794 5735 -1.0% 1.01x
ArrayAppendToFromGeneric 214128 211263 -1.3% 1.01x
ObjectiveCBridgeStubToNSDate 13371 13264 -0.8% 1.01x(?)
StringInterpolation 15130 14984 -1.0% 1.01x(?)
ErrorHandling 3602 3574 -0.8% 1.01x(?)
ArrayLiteral 1170 1161 -0.8% 1.01x(?)
ProtocolDispatch2 461 458 -0.7% 1.01x
ObjectiveCBridgeToNSArray 29354 29008 -1.2% 1.01x(?)
ArrayAppendFromGeneric 214019 211196 -1.3% 1.01x
Hanoi 18712 18608 -0.6% 1.01x
UTF8Decode 43580 43320 -0.6% 1.01x(?)
NopDeinit 42572 42174 -0.9% 1.01x(?)
Phonebook 20175 20058 -0.6% 1.01x
ArrayAppendToGeneric 214133 211291 -1.3% 1.01x
RGBHistogramOfObjects 79109 78597 -0.7% 1.01x(?)
ObjectiveCBridgeStubNSDateRefAccess 1167 1153 -1.2% 1.01x
DeadArray 114403 113723 -0.6% 1.01x(?)
BitCount 92 91 -1.1% 1.01x
ArrayValueProp3 2913 2882 -1.1% 1.01x(?)
ArrayValueProp4 2859 2831 -1.0% 1.01x(?)
ObserverPartiallyAppliedMethod 7965 7920 -0.6% 1.01x
ArraySubscript 5315 5313 -0.0% 1.00x(?)
ObjectiveCBridgeToNSString 1039 1037 -0.2% 1.00x(?)
DictionarySwapOfObjects 18834 18844 +0.1% 1.00x(?)
StackPromo 121310 121846 +0.4% 1.00x(?)
ObjectiveCBridgeFromNSDictionaryAnyObject 161734 161909 +0.1% 1.00x(?)
RecursiveOwnedParameter 10255 10220 -0.3% 1.00x(?)
ObjectiveCBridgeStubToNSString 1259 1261 +0.2% 1.00x(?)
ClassArrayGetter 1204 1204 +0.0% 1.00x
Array2D 770372 770636 +0.0% 1.00x(?)
MonteCarloPi 50701 50567 -0.3% 1.00x
StringWithCString 144265 144331 +0.1% 1.00x(?)
ObjectiveCBridgeFromNSStringForced 2917 2918 +0.0% 1.00x(?)
Prims 11991 12042 +0.4% 1.00x(?)
ObjectiveCBridgeFromNSString 4295 4297 +0.1% 1.00x(?)
PopFrontArray 12867 12856 -0.1% 1.00x(?)
Dictionary3OfObjects 2076 2080 +0.2% 1.00x(?)
RangeAssignment 6757 6780 +0.3% 1.00x(?)
ByteSwap 9 9 +0.0% 1.00x
ArrayAppendGenericStructs 1185 1188 +0.2% 1.00x(?)
SuperChars 253070 251950 -0.4% 1.00x(?)
ArrayAppendLazyMap 240398 241474 +0.5% 1.00x(?)
XorLoop 18877 18871 -0.0% 1.00x(?)
ObserverClosure 6646 6627 -0.3% 1.00x(?)
Integrate 347 348 +0.3% 1.00x(?)
ArrayAppendStrings 11088 11087 -0.0% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObject 80918 80552 -0.5% 1.00x(?)
Walsh 12601 12605 +0.0% 1.00x(?)
Dictionary3 1345 1340 -0.4% 1.00x(?)
Dictionary2 3435 3445 +0.3% 1.00x(?)
StringHasPrefix 1580 1584 +0.2% 1.00x(?)
SetIntersect_OfObjects 11375 11407 +0.3% 1.00x(?)
Join 1389 1392 +0.2% 1.00x(?)
ArrayOfRef 8380 8409 +0.3% 1.00x(?)
ObserverUnappliedMethod 8246 8247 +0.0% 1.00x(?)
ObjectiveCBridgeToNSSet 35744 35629 -0.3% 1.00x(?)
ArrayPlusEqualArrayOfInt 607 607 +0.0% 1.00x
DictionaryOfObjects 4362 4369 +0.2% 1.00x(?)
ObjectiveCBridgeStubToNSDateRef 3158 3164 +0.2% 1.00x(?)
PopFrontArrayGeneric 9014 8992 -0.2% 1.00x(?)
PopFrontUnsafePointer 153654 153394 -0.2% 1.00x(?)
StringEqualPointerComparison 9189 9166 -0.2% 1.00x(?)
PolymorphicCalls 1087 1083 -0.4% 1.00x(?)
RC4 8853 8860 +0.1% 1.00x(?)
ObjectiveCBridgeStubToNSStringRef 147 147 +0.0% 1.00x
MapReduce 42321 42286 -0.1% 1.00x(?)
IterateData 9507 9533 +0.3% 1.00x(?)
DictionaryLiteral 15110 15067 -0.3% 1.00x(?)
DictionaryRemoveOfObjects 45407 45274 -0.3% 1.00x(?)
SetIsSubsetOf 1813 1809 -0.2% 1.00x(?)
Dictionary 1760 1755 -0.3% 1.00x
SetIntersect 10614 10616 +0.0% 1.00x(?)
ObjectiveCBridgeStubDataAppend 3306 3310 +0.1% 1.00x(?)
SetExclusiveOr 19520 19502 -0.1% 1.00x(?)
NSDictionaryCastToSwift 5782 5758 -0.4% 1.00x(?)
ArrayAppendOptionals 1189 1188 -0.1% 1.00x(?)
ArrayInClass 3734 3734 +0.0% 1.00x
ArrayOfGenericRef 9269 9303 +0.4% 1.00x(?)
Sim2DArray 13951 13955 +0.0% 1.00x(?)
SetExclusiveOr_OfObjects 37260 37280 +0.1% 1.00x(?)
ArrayAppendRepeatCol 198000 198808 +0.4% 1.00x
ObjectiveCBridgeToNSDictionary 57410 57287 -0.2% 1.00x(?)
MonteCarloE 102363 102322 -0.0% 1.00x(?)
SetUnion_OfObjects 26654 26639 -0.1% 1.00x(?)
StringHasSuffixUnicode 60845 61138 +0.5% 1.00x
HashTest 5023 5002 -0.4% 1.00x(?)
SetIsSubsetOf_OfObjects 1774 1778 +0.2% 1.00x(?)
ArrayAppend 3352 3354 +0.1% 1.00x(?)
DictionaryRemove 16960 16957 -0.0% 1.00x(?)
151 5889600 5884576 -0.1% 1.00x
LinkedList 26346 26325 -0.1% 1.00x(?)
RGBHistogram 32744 32677 -0.2% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectForced 7113 7111 -0.0% 1.00x(?)
ArrayAppendArrayOfInt 606 606 +0.0% 1.00x
StringBuilder 2582 2574 -0.3% 1.00x(?)
ObserverForwarderStruct 4976 4960 -0.3% 1.00x(?)
ArrayValueProp2 2975 2979 +0.1% 1.00x(?)
AngryPhonebook 2807 2817 +0.4% 1.00x(?)
ArrayValueProp 2473 2478 +0.2% 1.00x(?)
GlobalClass 0 0 +0.0% 1.00x
Memset 19794 19796 +0.0% 1.00x(?)
Dictionary2OfObjects 5621 5626 +0.1% 1.00x(?)
ArrayAppendReserved 3118 3116 -0.1% 1.00x(?)
TwoSum 4547 4539 -0.2% 1.00x(?)
SevenBoom 1422 1424 +0.1% 1.00x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToString 93122 94487 +1.5% 0.99x(?)
Histogram 9379 9460 +0.9% 0.99x(?)
DictionaryBridge 3239 3269 +0.9% 0.99x(?)
ObjectiveCBridgeStubFromNSString 767 773 +0.8% 0.99x
ObjectAllocation 518 524 +1.2% 0.99x(?)
CaptureProp 94009 95355 +1.4% 0.99x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 106757 107949 +1.1% 0.99x(?)
ObjectiveCBridgeStubToArrayOfNSString 27983 28125 +0.5% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObject 72000 72565 +0.8% 0.99x(?)
ObjectiveCBridgeFromNSSetAnyObjectToString 118569 119514 +0.8% 0.99x(?)
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 82860 83365 +0.6% 0.99x(?)
NSStringConversion 1237 1247 +0.8% 0.99x(?)
SetUnion 11289 11407 +1.1% 0.99x(?)
ObjectiveCBridgeStubNSDateMutationRef 13427 13504 +0.6% 0.99x(?)
ObjectiveCBridgeStubNSDataAppend 2614 2647 +1.3% 0.99x(?)
ObjectiveCBridgeStubFromNSDateRef 3862 3933 +1.8% 0.98x
ObjectiveCBridgeStubURLAppendPathRef 220614 224748 +1.9% 0.98x(?)
ObjectiveCBridgeStubURLAppendPath 223400 227991 +2.1% 0.98x(?)
StringHasSuffix 1668 1695 +1.6% 0.98x
StringHasPrefixUnicode 14600 14879 +1.9% 0.98x
StringWalk 21499 21864 +1.7% 0.98x
ObjectiveCBridgeStubFromNSDate 3621 3680 +1.6% 0.98x
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 171644 176118 +2.6% 0.97x(?)
ArrayOfPOD 1737 1792 +3.2% 0.97x
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 85489 88212 +3.2% 0.97x(?)
ObjectiveCBridgeStubFromArrayOfNSString 54352 55850 +2.8% 0.97x(?)
ObjectiveCBridgeFromNSArrayAnyObjectForced 9758 10193 +4.5% 0.96x(?)
StrToInt 5462 5701 +4.4% 0.96x
**Hardware Overview** Model Name: Mac mini Model Identifier: Macmini7,1 Processor Name: Intel Core i7 Processor Speed: 3 GHz Number of Processors: 1 Total Number of Cores: 2 L2 Cache (per Core): 256 KB L3 Cache: 4 MB Memory: 16 GB

@natecook1000 natecook1000 requested a review from dabrahams January 5, 2017 04:10
Copy link
Contributor

@dabrahams dabrahams left a comment

Choose a reason for hiding this comment

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

Really glad you've done this, Nate! Looks like good work; I just have a few questions.

${"" if p else ", C.Iterator.Element : Comparable"}
{
// Possible starting states for elements at a, b, and c:
// 123, 132, 213, 231, 312, 321, 112, 121, 211, 122, 212, 221, 111
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't you going to show me how a, b, and c relate to this collection?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added some more comments here and above—pls let me know if that's what you were looking for.

_ elements: inout C,
_ a: C.Index, _ b: C.Index, _ c: C.Index
${", by areInIncreasingOrder: (C.Iterator.Element, C.Iterator.Element) -> Bool" if p else ""}
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't this declared in an extension to MutableCollection & RandomAccessCollection?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we finally route everything through one sort implementation that takes a closure, rather than gyb'ing, without regressing performance? A weak optimizer that may have since been fixed is the only reason we're gyb'ing this code. @bob-wilson what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm following the rest of the functions in the file, here. It would be great to have all of these as extension methods and to get rid of the gyb—I can try those changes out after we get this merged.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unless I'm missing something, getting rid of gyb and using extension methods are totally orthogonal concerns.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know the history of this or why you had to gyb the code, but regardless, if the optimizer has improved to let you get rid of that without regressing performance, that would be great.

let pivot = elements[range.lowerBound]
// Sort the first, middle, and last elements, then use the middle value
// as the pivot for the partition.
let half = elements.distance(from: lo, to: hi) / 2
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that this is a signed integers that is always positive we probably either want to convert it to unsigned or use a right-shift to divide by 2.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm—IndexDistance is a SignedInteger, which doesn't have bit shifts, and there's no easy unsigned conversion. Is this better than the above?

let half = numericCast(elements.distance(from: lo, to: hi)) / 2 as UInt
let mid = elements.index(lo, offsetBy: numericCast(half))

Copy link
Contributor

Choose a reason for hiding this comment

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

Unless we think we need to support sorting of huge files on 32-bit platforms, it might be. This will be awkward until we get the new integer protocols, so maybe you should insert a FIXME to use bitshifts once the new protocols come online. By the way, though, let's put the explicit type coercion next to the numericCast, OK?

let half = numericCast(elements.distance(from: lo, to: hi)) as UInt / 2

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, thanks!

elements.formIndex(after: &lo)
while lo != hi {
if !${cmp("elements[lo]", "pivot", p)} { break FindLo }
elements.formIndex(after: &lo)
}
break Loop
} while false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good transformation, but do we even need the do { ... } scope? It looks like we could dump it.

Copy link
Member Author

Choose a reason for hiding this comment

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

We need labeled scopes that break FindLo and break FindHi can break out of. The refactored versions I can come up with end up duplicating the lo != hi bounds checks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I overlooked the inner breaks. No problem here, then.

@@ -190,7 +237,7 @@ func _introSortImpl<C>(
depthLimit: depthLimit &- 1)
_introSortImpl(
&elements,
subRange: (elements.index(after: partIdx))..<range.upperBound,
subRange: partIdx..<range.upperBound,
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this an unintentional change? If not, why not?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's an intentional change. Because the previous implementation of _partition slotted the pivot element into partIdx as its final step, the elements were always arranged such that everything in range.lowerBound..<partIndex was less than elements[partIdx] and in elements.index(after: partIdx)..<range.upperBound was greater than or equal to elements[partIdx].

The new version doesn't have that guarantee, only that everything in range.lowerBound..<partIdx is less than everything in partIdx..<range.upperBound, so the sort of the upper partition needs to include the partitioning index.

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM; thanks for explaining.

@@ -262,6 +310,7 @@ func _heapify<C>(
${", by: areInIncreasingOrder" if p else ""})
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Not that these are particularly bad, but we try to avoid whitespace-only changes, for the record.

Copy link
Member Author

Choose a reason for hiding this comment

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

Noted, thanks!

@dabrahams
Copy link
Contributor

dabrahams commented Jan 5, 2017

I guess this is the only thing I feel should be fixed: #6382 (comment)

@@ -86,7 +90,8 @@ func _sort3<C>(
C : MutableCollection & RandomAccessCollection
${"" if p else ", C.Iterator.Element : Comparable"}
{
// Possible starting states for elements at a, b, and c:
// Possible starting orderings for elements at `elements[a]`, `elements[b]`,
// and `elements[c]`:
Copy link
Contributor

Choose a reason for hiding this comment

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

The change just made the text longer without addressing my point, which I obviously failed to articulate well. What I don't see is where a, b, and c fall in the sequence below. For example, if you wrote:

// 123, 132, 213, 231, 312, 321, 112, 121, 211, 122, 212, 221, 111
// ^                                  ^                   ^
// a                                  b                   c

I would understand the scenario.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I completely get it—I don't know why I made that list look so much like a collection! I've updated those comments; please let me know if those make more sense. I'm trying to make the flow of the different cases clear, since there's some subtlety due to keeping the sort stable.

@natecook1000
Copy link
Member Author

@swift-ci Please smoke test

@natecook1000 natecook1000 merged commit 6368857 into swiftlang:master Jan 6, 2017
@natecook1000 natecook1000 deleted the nc-sort-median branch October 13, 2017 16:07
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.

6 participants