Skip to content

stdlib: some small improvements for Dictionary and Set #4887

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 7 commits into from
Sep 21, 2016

Conversation

eeckstein
Copy link
Contributor

For details see the commit messages

@eeckstein
Copy link
Contributor Author

@swift-ci Please test

@eeckstein
Copy link
Contributor Author

@moiseev, @dabrahams, alexis: can you please take a look at this?

@eeckstein
Copy link
Contributor Author

@swift-ci Please benchmark

@Gankra
Copy link
Contributor

Gankra commented Sep 20, 2016

Hey there, this is Alexis!

@swift-ci
Copy link
Contributor

Build comment file:

Optimized (O)

Regression (6)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
SetExclusiveOr_OfObjects 8574 10701 +24.8% 0.80x
SetUnion_OfObjects 7204 8869 +23.1% 0.81x
SetIntersect_OfObjects 2285 2664 +16.6% 0.86x
SetIsSubsetOf_OfObjects 525 575 +9.5% 0.91x
StrToInt 4781 5194 +8.6% 0.92x
ObjectiveCBridgeStubFromNSDate 3611 3838 +6.3% 0.94x

Improvement (14)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
ObjectiveCBridgeFromNSSetAnyObjectForced 4544 4296 -5.5% 1.06x(?)
TwoSum 1711 1599 -6.5% 1.07x
ClassArrayGetter 13 12 -7.7% 1.08x(?)
ObjectiveCBridgeFromNSSetAnyObjectToString 154323 143052 -7.3% 1.08x
DictionaryRemove 4994 4611 -7.7% 1.08x
CaptureProp 4563 4203 -7.9% 1.09x
RGBHistogram 3045 2806 -7.8% 1.09x
SetIntersect 1186 1075 -9.4% 1.10x
ObjectiveCBridgeStubNSDateRefAccess 338 308 -8.9% 1.10x
Prims 789 708 -10.3% 1.11x
DictionarySwap 702 627 -10.7% 1.12x
OpenClose 54 48 -11.1% 1.12x
SetExclusiveOr 3832 2831 -26.1% 1.35x
SetUnion 3437 2347 -31.7% 1.46x

No Changes (116)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
Histogram 686 656 -4.4% 1.05x
Walsh 325 310 -4.6% 1.05x
ObjectiveCBridgeFromNSDictionaryAnyObject 213118 205364 -3.6% 1.04x
StringHasSuffix 718 690 -3.9% 1.04x
ObjectiveCBridgeStubFromNSStringRef 140 134 -4.3% 1.04x
ObjectiveCBridgeFromNSSetAnyObject 272713 262153 -3.9% 1.04x(?)
ObjectiveCBridgeStubToNSDateRef 3477 3328 -4.3% 1.04x(?)
NopDeinit 38157 36676 -3.9% 1.04x
ObjectiveCBridgeToNSDictionary 16718 16295 -2.5% 1.03x(?)
ObjectiveCBridgeStubNSDataAppend 2463 2402 -2.5% 1.03x
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 92495 89630 -3.1% 1.03x(?)
ObjectiveCBridgeStubNSDateMutationRef 12163 11851 -2.6% 1.03x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 141066 138143 -2.1% 1.02x(?)
SetIsSubsetOf 515 504 -2.1% 1.02x
ObjectiveCBridgeFromNSArrayAnyObject 76573 75368 -1.6% 1.02x(?)
DeadArray 185 182 -1.6% 1.02x
ObjectiveCBridgeStubFromArrayOfNSString 58837 57423 -2.4% 1.02x(?)
Dictionary2OfObjects 3465 3412 -1.5% 1.02x(?)
ArraySubscript 1416 1405 -0.8% 1.01x
135 3061153 3023551 -1.2% 1.01x
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 216202 213575 -1.2% 1.01x(?)
DictionaryBridge 3898 3861 -0.9% 1.01x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 5066 5039 -0.5% 1.01x
ObjectiveCBridgeFromNSStringForced 2636 2613 -0.9% 1.01x
ObjectiveCBridgeStubToNSDate 13317 13250 -0.5% 1.01x(?)
StringInterpolation 10978 10832 -1.3% 1.01x(?)
ObjectiveCBridgeStubToNSString 1288 1280 -0.6% 1.01x
ArrayOfRef 3553 3511 -1.2% 1.01x
ObjectiveCBridgeToNSSet 15954 15837 -0.7% 1.01x(?)
PopFrontArrayGeneric 1129 1122 -0.6% 1.01x
ObjectiveCBridgeStubToNSStringRef 125 124 -0.8% 1.01x(?)
DictionaryLiteral 2781 2765 -0.6% 1.01x(?)
UTF8Decode 290 288 -0.7% 1.01x
ObjectiveCBridgeFromNSString 1823 1803 -1.1% 1.01x
MonteCarloE 10569 10442 -1.2% 1.01x(?)
HashTest 1758 1745 -0.7% 1.01x
ObjectiveCBridgeToNSString 1079 1076 -0.3% 1.00x
PopFrontArray 1126 1128 +0.2% 1.00x(?)
RecursiveOwnedParameter 1933 1935 +0.1% 1.00x(?)
Integrate 239 238 -0.4% 1.00x
Array2D 1979 1983 +0.2% 1.00x(?)
MonteCarloPi 45044 45195 +0.3% 1.00x
StringWithCString 151272 151494 +0.1% 1.00x
ObjectiveCBridgeFromNSArrayAnyObjectForced 6017 6044 +0.5% 1.00x
SortLettersInPlace 979 978 -0.1% 1.00x(?)
RangeAssignment 285 284 -0.3% 1.00x(?)
StringHasPrefix 609 609 +0.0% 1.00x
ByteSwap 0 0 +0.0% 1.00x
SuperChars 216094 215715 -0.2% 1.00x(?)
XorLoop 380 381 +0.3% 1.00x
Join 463 463 +0.0% 1.00x
ObjectiveCBridgeStubFromNSString 785 788 +0.4% 1.00x(?)
ProtocolDispatch 3043 3040 -0.1% 1.00x(?)
ObjectAllocation 153 153 +0.0% 1.00x
TypeFlood 0 0 +0.0% 1.00x
StrComplexWalk 2904 2896 -0.3% 1.00x(?)
ErrorHandling 2981 2967 -0.5% 1.00x(?)
ObjectiveCBridgeStubDateMutation 273 273 +0.0% 1.00x
NSError 325 326 +0.3% 1.00x(?)
StringEqualPointerComparison 7322 7314 -0.1% 1.00x(?)
PolymorphicCalls 22 22 +0.0% 1.00x
MapReduce 343 343 +0.0% 1.00x
AngryPhonebook 2823 2828 +0.2% 1.00x(?)
ArrayOfGenericPOD 220 220 +0.0% 1.00x
DictionaryRemoveOfObjects 20437 20338 -0.5% 1.00x(?)
SortStringsUnicode 8244 8222 -0.3% 1.00x
ObjectiveCBridgeStubDataAppend 3000 2996 -0.1% 1.00x(?)
StringBuilder 1317 1321 +0.3% 1.00x
ArrayInClass 62 62 +0.0% 1.00x
ArrayOfGenericRef 3593 3604 +0.3% 1.00x(?)
ObjectiveCBridgeStubDateAccess 182 182 +0.0% 1.00x
Sim2DArray 277 277 +0.0% 1.00x
RC4 165 165 +0.0% 1.00x
ArrayAppend 773 773 +0.0% 1.00x
StringHasPrefixUnicode 13934 13969 +0.2% 1.00x(?)
LinkedList 7257 7256 -0.0% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 110540 110455 -0.1% 1.00x(?)
ArrayAppendReserved 536 537 +0.2% 1.00x(?)
ArrayOfPOD 182 182 +0.0% 1.00x
BitCount 1 1 +0.0% 1.00x
ArrayLiteral 1176 1180 +0.3% 1.00x
SevenBoom 1353 1347 -0.4% 1.00x(?)
StringWalk 5885 5887 +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
ArrayValueProp4 6 6 +0.0% 1.00x
ArrayValueProp2 6 6 +0.0% 1.00x
ArrayValueProp3 6 6 +0.0% 1.00x
DictionarySwapOfObjects 6995 7065 +1.0% 0.99x
StackPromo 21805 21994 +0.9% 0.99x
ObjectiveCBridgeFromNSArrayAnyObjectToString 116102 117126 +0.9% 0.99x(?)
Dictionary3OfObjects 863 871 +0.9% 0.99x
StringHasSuffixUnicode 63053 63538 +0.8% 0.99x
AnyHashableWithAClass 61842 62581 +1.2% 0.99x
ProtocolDispatch2 157 158 +0.6% 0.99x
ObjectiveCBridgeStubURLAppendPathRef 240540 241891 +0.6% 0.99x(?)
DictionaryOfObjects 2316 2333 +0.7% 0.99x
PopFrontUnsafePointer 9184 9276 +1.0% 0.99x(?)
Dictionary 776 787 +1.4% 0.99x
ObjectiveCBridgeStubToArrayOfNSString 29546 29767 +0.8% 0.99x(?)
StaticArray 2837 2905 +2.4% 0.98x(?)
IterateData 2542 2597 +2.2% 0.98x
ObjectiveCBridgeStubURLAppendPath 236704 241126 +1.9% 0.98x(?)
NSDictionaryCastToSwift 7102 7230 +1.8% 0.98x(?)
Phonebook 7496 7671 +2.3% 0.98x
NSStringConversion 832 845 +1.6% 0.98x
SortStrings 1771 1819 +2.7% 0.97x
ObjectiveCBridgeStubFromNSDateRef 3686 3802 +3.1% 0.97x
Dictionary2 2066 2129 +3.0% 0.97x(?)
RGBHistogramOfObjects 22288 23047 +3.4% 0.97x
Chars 622 642 +3.2% 0.97x
ObjectiveCBridgeToNSArray 29572 30735 +3.9% 0.96x(?)
Hanoi 3335 3486 +4.5% 0.96x
Dictionary3 519 548 +5.6% 0.95x
Calculator 35 37 +5.7% 0.95x
**Unoptimized (Onone)**

Regression (1)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
PopFrontUnsafePointer 243884 259261 +6.3% 0.94x

Improvement (19)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
Dictionary3OfObjects 2383 2254 -5.4% 1.06x
Dictionary2 4640 4365 -5.9% 1.06x
Dictionary 2278 2156 -5.4% 1.06x(?)
DictionarySwapOfObjects 22739 21228 -6.6% 1.07x
SetExclusiveOr 32521 30418 -6.5% 1.07x
ObjectiveCBridgeToNSDictionary 16913 15860 -6.2% 1.07x(?)
Dictionary3 1738 1604 -7.7% 1.08x
SetIntersect 16234 15092 -7.0% 1.08x
DictionaryRemove 18867 17400 -7.8% 1.08x
ObjectiveCBridgeFromNSDictionaryAnyObject 228977 210735 -8.0% 1.09x
DictionaryRemoveOfObjects 51335 47082 -8.3% 1.09x
StringHasSuffix 1756 1618 -7.9% 1.09x
SetIsSubsetOf_OfObjects 2523 2305 -8.6% 1.09x
SetIsSubsetOf 2692 2457 -8.7% 1.10x
SetExclusiveOr_OfObjects 51268 46655 -9.0% 1.10x
SetUnion 20242 18421 -9.0% 1.10x
SetUnion_OfObjects 37996 34193 -10.0% 1.11x
SetIntersect_OfObjects 15620 13895 -11.0% 1.12x
TypeFlood 226 176 -22.1% 1.28x(?)

No Changes (116)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
DictionarySwap 7982 7615 -4.6% 1.05x
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 144974 138399 -4.5% 1.05x
TwoSum 6884 6575 -4.5% 1.05x
StrComplexWalk 7622 7363 -3.4% 1.04x
ObjectiveCBridgeToNSSet 16528 15828 -4.2% 1.04x(?)
DictionaryOfObjects 5075 4867 -4.1% 1.04x
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 124931 119855 -4.1% 1.04x(?)
Dictionary2OfObjects 6501 6267 -3.6% 1.04x(?)
Histogram 12112 11801 -2.6% 1.03x(?)
ObjectiveCBridgeFromNSSetAnyObject 279288 271512 -2.8% 1.03x
ObjectiveCBridgeToNSArray 30741 29933 -2.6% 1.03x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToString 124859 121525 -2.7% 1.03x(?)
Calculator 949 922 -2.9% 1.03x
ObjectiveCBridgeFromNSArrayAnyObject 79972 77677 -2.9% 1.03x(?)
RGBHistogram 45439 44323 -2.5% 1.03x(?)
ObjectiveCBridgeStubFromNSDate 4060 3954 -2.6% 1.03x
StackPromo 130894 128480 -1.8% 1.02x(?)
135 5687736 5561702 -2.2% 1.02x
ObjectiveCBridgeStubFromNSString 834 819 -1.8% 1.02x
CaptureProp 119741 116845 -2.4% 1.02x
PolymorphicCalls 1159 1141 -1.6% 1.02x
DictionaryLiteral 16981 16594 -2.3% 1.02x
ObjectiveCBridgeStubDataAppend 3453 3384 -2.0% 1.02x
StringHasPrefixUnicode 15848 15574 -1.7% 1.02x
RGBHistogramOfObjects 95921 94030 -2.0% 1.02x
ObjectiveCBridgeStubFromArrayOfNSString 59626 58547 -1.8% 1.02x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 226027 224636 -0.6% 1.01x(?)
DictionaryBridge 3970 3924 -1.2% 1.01x(?)
Prims 13610 13503 -0.8% 1.01x
SuperChars 267302 265820 -0.6% 1.01x(?)
ObjectiveCBridgeStubToNSDate 13877 13743 -1.0% 1.01x(?)
StringInterpolation 15826 15652 -1.1% 1.01x
ObjectiveCBridgeStubURLAppendPathRef 240323 238592 -0.7% 1.01x(?)
PopFrontArrayGeneric 9600 9530 -0.7% 1.01x(?)
UTF8Decode 44069 43577 -1.1% 1.01x(?)
ObjectiveCBridgeStubToArrayOfNSString 29671 29272 -1.3% 1.01x(?)
NSDictionaryCastToSwift 8442 8321 -1.4% 1.01x(?)
ObjectiveCBridgeFromNSString 5013 4987 -0.5% 1.01x(?)
NSStringConversion 2987 2959 -0.9% 1.01x(?)
ObjectiveCBridgeFromNSSetAnyObjectForced 7467 7412 -0.7% 1.01x(?)
StringBuilder 2795 2774 -0.8% 1.01x(?)
ObjectiveCBridgeStubNSDataAppend 2906 2883 -0.8% 1.01x(?)
ArraySubscript 5644 5641 -0.1% 1.00x(?)
ObjectiveCBridgeToNSString 1109 1106 -0.3% 1.00x
MonteCarloPi 53509 53495 -0.0% 1.00x(?)
PopFrontArray 24322 24210 -0.5% 1.00x(?)
RecursiveOwnedParameter 10972 10930 -0.4% 1.00x(?)
ObjectiveCBridgeStubToNSString 1335 1335 +0.0% 1.00x
AnyHashableWithAClass 77682 77354 -0.4% 1.00x(?)
ClassArrayGetter 1265 1266 +0.1% 1.00x(?)
Array2D 812893 812935 +0.0% 1.00x(?)
ObjectiveCBridgeStubFromNSDateRef 4142 4142 +0.0% 1.00x
ArrayOfGenericPOD 3522 3524 +0.1% 1.00x(?)
StringWithCString 155885 156177 +0.2% 1.00x(?)
ObjectiveCBridgeFromNSArrayAnyObjectForced 10337 10381 +0.4% 1.00x(?)
ObjectiveCBridgeFromNSStringForced 3009 3023 +0.5% 1.00x(?)
SortLettersInPlace 2580 2573 -0.3% 1.00x
RangeAssignment 27651 27651 +0.0% 1.00x
ByteSwap 9 9 +0.0% 1.00x
XorLoop 20004 19994 -0.1% 1.00x(?)
Integrate 368 368 +0.0% 1.00x
ProtocolDispatch 6177 6173 -0.1% 1.00x(?)
ArrayLiteral 1245 1248 +0.2% 1.00x
ProtocolDispatch2 441 441 +0.0% 1.00x
Join 1461 1459 -0.1% 1.00x(?)
ArrayOfRef 9409 9385 -0.3% 1.00x(?)
ObjectiveCBridgeStubDateMutation 517 517 +0.0% 1.00x
MapReduce 45891 45745 -0.3% 1.00x(?)
IterateData 10655 10656 +0.0% 1.00x(?)
SortStringsUnicode 9355 9313 -0.5% 1.00x
NopDeinit 58103 58136 +0.1% 1.00x(?)
ObjectiveCBridgeStubNSDateRefAccess 1292 1289 -0.2% 1.00x
ArrayInClass 3961 3962 +0.0% 1.00x(?)
ArrayOfGenericRef 10071 10047 -0.2% 1.00x(?)
Phonebook 64183 64111 -0.1% 1.00x(?)
Sim2DArray 14787 14782 -0.0% 1.00x
MonteCarloE 109161 108931 -0.2% 1.00x
RC4 9392 9405 +0.1% 1.00x
HashTest 5390 5405 +0.3% 1.00x
ArrayAppend 3341 3337 -0.1% 1.00x(?)
LinkedList 27987 27925 -0.2% 1.00x(?)
ArrayAppendReserved 3104 3106 +0.1% 1.00x(?)
ArrayOfPOD 2452 2449 -0.1% 1.00x(?)
Chars 5118 5122 +0.1% 1.00x(?)
DeadArray 121976 121695 -0.2% 1.00x(?)
BitCount 96 96 +0.0% 1.00x
AngryPhonebook 3017 3012 -0.2% 1.00x
SevenBoom 1506 1511 +0.3% 1.00x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 92126 92171 +0.1% 1.00x(?)
ArrayValueProp 2622 2626 +0.1% 1.00x(?)
GlobalClass 0 0 +0.0% 1.00x
Memset 20960 20969 +0.0% 1.00x(?)
ArrayValueProp4 3005 2998 -0.2% 1.00x
ArrayValueProp2 3184 3190 +0.2% 1.00x(?)
ArrayValueProp3 3058 3065 +0.2% 1.00x
ErrorHandling 3786 3832 +1.2% 0.99x(?)
ObjectiveCBridgeStubFromNSStringRef 171 172 +0.6% 0.99x(?)
StaticArray 35308 35818 +1.4% 0.99x
ObjectAllocation 561 566 +0.9% 0.99x
StringHasSuffixUnicode 64741 65163 +0.7% 0.99x(?)
Walsh 13234 13326 +0.7% 0.99x(?)
ObjectiveCBridgeStubToNSDateRef 3350 3368 +0.5% 0.99x
StringEqualPointerComparison 9535 9611 +0.8% 0.99x
ObjectiveCBridgeStubToNSStringRef 163 164 +0.6% 0.99x
Hanoi 20228 20331 +0.5% 0.99x
ObjectiveCBridgeStubURLAppendPath 241114 244048 +1.2% 0.99x(?)
ObjectiveCBridgeFromNSSetAnyObjectToString 163272 164897 +1.0% 0.99x(?)
ObjectiveCBridgeStubDateAccess 1084 1096 +1.1% 0.99x
StringWalk 21026 21247 +1.1% 0.99x
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 7449 7582 +1.8% 0.98x(?)
OpenClose 451 460 +2.0% 0.98x
StrToInt 5208 5290 +1.6% 0.98x
SortStrings 2715 2797 +3.0% 0.97x
StringHasPrefix 1664 1722 +3.5% 0.97x
ObjectiveCBridgeStubNSDateMutationRef 14570 15123 +3.8% 0.96x(?)
NSError 668 701 +4.9% 0.95x(?)
**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: 8 GB

@eeckstein
Copy link
Contributor Author

@swift-ci Please smoke test

@eeckstein
Copy link
Contributor Author

@swift-ci Please benchmark

@eeckstein
Copy link
Contributor Author

@swift-ci Please smoke test

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci Please smoke test

Copy link
Contributor

@Gankra Gankra left a comment

Choose a reason for hiding this comment

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

The changes here seem basically fine. Most of my comments are minor pedantry or idle curiosity since I'm still feeling out the designs at play here, and the best practices for the standard libs.

@@ -2523,7 +2523,7 @@ final internal class _Native${Self}StorageImpl<${TypeParameters}> {

@_versioned
internal var _capacity: Int {
return _body.capacity
return _assumeNonNegative(_body.capacity)
Copy link
Contributor

@Gankra Gankra Sep 20, 2016

Choose a reason for hiding this comment

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

If only there were some way to communicate this in the type system... 🤔

Which remaining assertions is this eliminating after you've moved all these checks to debug-only?

Note from my own digging in the compiler: this is lowered to value ranges on loads (fast), and not llvm.assume (slow). Good!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually can't remember exactly, but there were some "< 0"-checks in llvm code.

@@ -72,54 +72,21 @@ HashingTestSuite.test("_mixInt/GoldenValues") {

HashingTestSuite.test("_squeezeHashValue/Int") {
// Check that the function can return values that cover the whole range.
func checkRange(_ r: Range<Int>) {
func checkRange(_ r: Int) {
var results = [Int : Void]()
Copy link
Contributor

@Gankra Gankra Sep 20, 2016

Choose a reason for hiding this comment

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

Since we're cleaning up in here: shouldn't this just be a Set<Int>? (or if you're interested in perf, an Array initialized to [false, false, false, ...])

Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, does this code predate Set? :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Set would be fine. I'll change it

checkRange(2)
checkRange(4)
checkRange(8)
checkRange(16)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Might as well toss a checkRange(1) in here as the ultimate degeneracy test? (just verifies _squeezeHashValue always returns 0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add it

@@ -2933,6 +2933,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
}

internal func assertingGet(_ i: Index) -> SequenceElement {
_precondition(i.offset >= 0 && i.offset < capacity)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this fixing an existing mem-safety bug, or just compensating for the removal of asserts elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's compensating for the removed precondition in isInitializedEntry (called in the next line)

@eeckstein
Copy link
Contributor Author

@swift-ci Please smoke test

@eeckstein
Copy link
Contributor Author

@swift-ci Please benchmark

func _squeezeHashValue(_ hashValue: Int, _ upperBound: Int) -> Int {
_sanityCheck(_isPowerOf2(upperBound))
let mixedHashValue = _mixInt(hashValue)
return mixedHashValue & (upperBound &- 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, this slipped my mind because I was expecting this code to exist already. I personally think its worth explaining this kind of strength reduction optimization to ensure the codebase can be maintained by non-experts. In this case just noting that this is an effecient idiom for x % bound for bounds that are a power of 2.

Copy link
Contributor

@dabrahams dabrahams Sep 20, 2016

Choose a reason for hiding this comment

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

Yes, absolutely. I often find I need to remind people to explain their low-level optimizations so I won't undo them later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add a comment

@@ -147,51 +147,28 @@ func _mixInt(_ value: Int) -> Int {
#endif
}

/// Given a hash value, returns an integer value within the given range that
/// corresponds to a hash value.
/// Given a hash value, returns an integer value between 0 and `upperBound`
Copy link
Contributor

@moiseev moiseev Sep 20, 2016

Choose a reason for hiding this comment

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

To be precise, can we say something like "an integer value in the range 0..<upperBound"? As it is not clear to me from this description whether upperBound is included or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change it

@swift-ci
Copy link
Contributor

Build comment file:

Optimized (O)

Regression (2)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
ObjectiveCBridgeFromNSSetAnyObject 310535 345143 +11.1% 0.90x(?)
ObjectiveCBridgeFromNSArrayAnyObjectForced 6330 6843 +8.1% 0.93x(?)

Improvement (12)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
DictionaryRemove 4897 4616 -5.7% 1.06x
ObjectiveCBridgeStubFromArrayOfNSString 77897 73196 -6.0% 1.06x(?)
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 137218 126594 -7.7% 1.08x
Prims 766 704 -8.1% 1.09x(?)
SetIntersect 1201 1093 -9.0% 1.10x
SetExclusiveOr_OfObjects 8228 7486 -9.0% 1.10x
SetUnion_OfObjects 6923 6270 -9.4% 1.10x
RGBHistogram 3094 2820 -8.9% 1.10x
TwoSum 1699 1540 -9.4% 1.10x
SetUnion 3425 3017 -11.9% 1.14x
DictionarySwap 765 624 -18.4% 1.23x
SetExclusiveOr 3933 2631 -33.1% 1.49x

No Changes (122)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
Histogram 678 647 -4.6% 1.05x
SetIntersect_OfObjects 2306 2188 -5.1% 1.05x
UTF8Decode 350 333 -4.9% 1.05x
ObjectiveCBridgeFromNSSetAnyObjectToString 189220 179550 -5.1% 1.05x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToString 151332 146664 -3.1% 1.03x(?)
DictionaryRemoveOfObjects 20209 19682 -2.6% 1.03x
ObjectiveCBridgeFromNSSetAnyObjectForced 5091 4960 -2.6% 1.03x(?)
ObjectiveCBridgeFromNSDictionaryAnyObject 264967 259432 -2.1% 1.02x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 5630 5526 -1.9% 1.02x(?)
PopFrontArray 1869 1838 -1.7% 1.02x
ObjectiveCBridgeStubFromNSStringRef 156 153 -1.9% 1.02x
Walsh 349 343 -1.7% 1.02x
ObjectiveCBridgeStubURLAppendPathRef 367096 360775 -1.7% 1.02x
ObjectiveCBridgeStubURLAppendPath 367399 359286 -2.2% 1.02x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 179246 175348 -2.2% 1.02x(?)
SetIsSubsetOf 511 501 -2.0% 1.02x
Dictionary 812 798 -1.7% 1.02x
ObjectiveCBridgeStubDataAppend 3322 3252 -2.1% 1.02x(?)
ObjectiveCBridgeStubNSDateMutationRef 12644 12344 -2.4% 1.02x(?)
ObjectiveCBridgeStubNSDataAppend 2808 2744 -2.3% 1.02x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 291523 289774 -0.6% 1.01x(?)
Dictionary3OfObjects 857 852 -0.6% 1.01x(?)
ObjectiveCBridgeStubToNSDate 14273 14148 -0.9% 1.01x(?)
Join 478 471 -1.5% 1.01x
Dictionary3 505 500 -1.0% 1.01x
Dictionary2 2039 2023 -0.8% 1.01x
ArrayAppend 768 764 -0.5% 1.01x
ObjectiveCBridgeStubToNSStringRef 138 136 -1.4% 1.01x
RGBHistogramOfObjects 22346 22128 -1.0% 1.01x
HashTest 1787 1766 -1.2% 1.01x(?)
ArrayOfPOD 186 185 -0.5% 1.01x
StringBuilder 1314 1298 -1.2% 1.01x(?)
DictionarySwapOfObjects 6773 6755 -0.3% 1.00x(?)
StackPromo 21536 21516 -0.1% 1.00x(?)
RecursiveOwnedParameter 1986 1986 +0.0% 1.00x
ObjectiveCBridgeStubToNSString 1253 1256 +0.2% 1.00x(?)
ClassArrayGetter 15 15 +0.0% 1.00x
Array2D 2811 2809 -0.1% 1.00x(?)
ArrayOfGenericPOD 223 223 +0.0% 1.00x
StringWithCString 146226 146461 +0.2% 1.00x
SortLettersInPlace 976 980 +0.4% 1.00x(?)
RangeAssignment 336 336 +0.0% 1.00x
StringHasPrefix 803 804 +0.1% 1.00x
ByteSwap 1 1 +0.0% 1.00x
SuperChars 203446 203061 -0.2% 1.00x(?)
XorLoop 406 406 +0.0% 1.00x
StringInterpolation 11077 11095 +0.2% 1.00x(?)
Integrate 248 249 +0.4% 1.00x
ObjectiveCBridgeStubFromNSString 922 921 -0.1% 1.00x(?)
ProtocolDispatch 3159 3157 -0.1% 1.00x
TypeFlood 0 0 +0.0% 1.00x
ProtocolDispatch2 149 149 +0.0% 1.00x
ErrorHandling 2978 2973 -0.2% 1.00x(?)
ArrayOfRef 3529 3524 -0.1% 1.00x(?)
ObjectiveCBridgeStubDateMutation 257 258 +0.4% 1.00x
ObjectiveCBridgeStubToNSDateRef 3272 3286 +0.4% 1.00x(?)
PopFrontUnsafePointer 9040 9043 +0.0% 1.00x(?)
StringEqualPointerComparison 8611 8608 -0.0% 1.00x(?)
CaptureProp 5737 5736 -0.0% 1.00x(?)
PolymorphicCalls 25 25 +0.0% 1.00x
MapReduce 390 390 +0.0% 1.00x
IterateData 2608 2620 +0.5% 1.00x
DictionaryLiteral 2868 2858 -0.3% 1.00x(?)
OpenClose 71 71 +0.0% 1.00x
NopDeinit 35841 35810 -0.1% 1.00x
ObjectiveCBridgeFromNSArrayAnyObject 90471 90424 -0.1% 1.00x(?)
GlobalClass 0 0 +0.0% 1.00x
ObjectiveCBridgeStubNSDateRefAccess 382 382 +0.0% 1.00x
ArrayInClass 86 86 +0.0% 1.00x
StringHasSuffix 918 918 +0.0% 1.00x
ObjectiveCBridgeStubDateAccess 229 229 +0.0% 1.00x
Sim2DArray 273 273 +0.0% 1.00x
MonteCarloPi 44408 44408 +0.0% 1.00x
MonteCarloE 10369 10413 +0.4% 1.00x
StringHasSuffixUnicode 73640 73639 -0.0% 1.00x(?)
SetIsSubsetOf_OfObjects 522 522 +0.0% 1.00x
ObjectiveCBridgeToNSSet 24243 24145 -0.4% 1.00x(?)
LinkedList 6409 6438 +0.5% 1.00x(?)
NSStringConversion 876 873 -0.3% 1.00x
ArrayValueProp4 8 8 +0.0% 1.00x
Chars 658 658 +0.0% 1.00x
DeadArray 201 201 +0.0% 1.00x
BitCount 1 1 +0.0% 1.00x
ArrayLiteral 1145 1146 +0.1% 1.00x(?)
SevenBoom 1377 1377 +0.0% 1.00x
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 112891 112418 -0.4% 1.00x(?)
StringWalk 7107 7105 -0.0% 1.00x(?)
ArrayValueProp 8 8 +0.0% 1.00x
ObjectiveCBridgeFromNSString 1932 1934 +0.1% 1.00x
RC4 156 156 +0.0% 1.00x
Dictionary2OfObjects 3332 3328 -0.1% 1.00x(?)
ArrayAppendReserved 515 516 +0.2% 1.00x
ArrayValueProp2 8 8 +0.0% 1.00x
ArrayValueProp3 8 8 +0.0% 1.00x
ArraySubscript 1410 1418 +0.6% 0.99x(?)
ObjectiveCBridgeFromNSStringForced 2876 2895 +0.7% 0.99x
StaticArray 2848 2866 +0.6% 0.99x(?)
ObjectAllocation 157 158 +0.6% 0.99x
AnyHashableWithAClass 64540 65168 +1.0% 0.99x
ObjectiveCBridgeToNSArray 31931 32139 +0.7% 0.99x(?)
NSError 329 332 +0.9% 0.99x
DictionaryOfObjects 2281 2293 +0.5% 0.99x(?)
AngryPhonebook 2831 2864 +1.2% 0.99x(?)
SortStringsUnicode 9168 9220 +0.6% 0.99x
ArrayOfGenericRef 3577 3628 +1.4% 0.99x
StringHasPrefixUnicode 15568 15726 +1.0% 0.99x
Memset 213 215 +0.9% 0.99x(?)
ObjectiveCBridgeToNSString 1055 1074 +1.8% 0.98x(?)
SortStrings 1910 1955 +2.4% 0.98x
ObjectiveCBridgeStubFromNSDateRef 3912 3973 +1.6% 0.98x
StrComplexWalk 3309 3369 +1.8% 0.98x
PopFrontArrayGeneric 1841 1873 +1.7% 0.98x(?)
Calculator 40 41 +2.5% 0.98x
Phonebook 7723 7902 +2.3% 0.98x
135 3743399 3845965 +2.7% 0.97x
ObjectiveCBridgeStubToArrayOfNSString 30569 31672 +3.6% 0.97x(?)
ObjectiveCBridgeToNSDictionary 24297 24959 +2.7% 0.97x(?)
ObjectiveCBridgeStubFromNSDate 3825 3950 +3.3% 0.97x(?)
Hanoi 3550 3717 +4.7% 0.96x
NSDictionaryCastToSwift 7142 7428 +4.0% 0.96x(?)
StrToInt 5256 5490 +4.5% 0.96x
DictionaryBridge 5697 5971 +4.8% 0.95x(?)
**Unoptimized (Onone)**

Regression (6)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
TypeFlood 174 204 +17.2% 0.85x(?)
ObjectiveCBridgeFromNSArrayAnyObjectForced 11889 13466 +13.3% 0.88x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 8611 9587 +11.3% 0.90x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToString 144983 157580 +8.7% 0.92x(?)
ObjectiveCBridgeFromNSString 5242 5704 +8.8% 0.92x(?)
PopFrontUnsafePointer 251021 265789 +5.9% 0.94x

Improvement (19)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
Dictionary2OfObjects 6792 6411 -5.6% 1.06x
ObjectiveCBridgeFromNSDictionaryAnyObject 278872 260539 -6.6% 1.07x(?)
DictionarySwap 8007 7480 -6.6% 1.07x
DictionaryRemoveOfObjects 50489 47223 -6.5% 1.07x(?)
DictionarySwapOfObjects 22847 21243 -7.0% 1.08x(?)
Dictionary2 4808 4424 -8.0% 1.09x(?)
SetExclusiveOr 34698 31828 -8.3% 1.09x
SetExclusiveOr_OfObjects 51418 47034 -8.5% 1.09x
DictionaryRemove 18885 17383 -8.0% 1.09x
DictionaryOfObjects 5489 4984 -9.2% 1.10x
ObjectiveCBridgeToNSDictionary 24828 22601 -9.0% 1.10x(?)
SetUnion_OfObjects 37788 34334 -9.1% 1.10x
Dictionary3OfObjects 2556 2302 -9.9% 1.11x
ObjectiveCBridgeFromNSArrayAnyObject 101172 91394 -9.7% 1.11x(?)
SetIntersect_OfObjects 15994 14340 -10.3% 1.12x
SetIsSubsetOf_OfObjects 2582 2304 -10.8% 1.12x
SetUnion 21144 18537 -12.3% 1.14x
Dictionary3 1868 1616 -13.5% 1.16x
NopDeinit 89760 63788 -28.9% 1.41x(?)

No Changes (111)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
Histogram 12703 12042 -5.2% 1.05x(?)
ObjectiveCBridgeStubToNSDate 14746 14045 -4.8% 1.05x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 176402 167347 -5.1% 1.05x(?)
Dictionary 2324 2207 -5.0% 1.05x(?)
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 142167 134757 -5.2% 1.05x(?)
StackPromo 130295 125270 -3.9% 1.04x(?)
ObjectiveCBridgeFromNSStringForced 3451 3316 -3.9% 1.04x(?)
SetIntersect 16946 16321 -3.7% 1.04x
NSDictionaryCastToSwift 9381 8983 -4.2% 1.04x(?)
StringHasSuffix 2124 2039 -4.0% 1.04x
RGBHistogram 48789 46805 -4.1% 1.04x
StrToInt 5953 5742 -3.5% 1.04x
StringWalk 25247 24310 -3.7% 1.04x
TwoSum 7198 6908 -4.0% 1.04x(?)
StringHasPrefix 2009 1952 -2.8% 1.03x
StrComplexWalk 8952 8701 -2.8% 1.03x
Calculator 1063 1032 -2.9% 1.03x
DictionaryLiteral 17275 16794 -2.8% 1.03x(?)
ObjectiveCBridgeStubToArrayOfNSString 31972 31033 -2.9% 1.03x
ObjectiveCBridgeFromNSSetAnyObjectToString 196711 190572 -3.1% 1.03x(?)
RGBHistogramOfObjects 100086 97454 -2.6% 1.03x(?)
DictionaryBridge 5984 5874 -1.8% 1.02x(?)
StringInterpolation 15880 15623 -1.6% 1.02x(?)
ObjectAllocation 561 550 -2.0% 1.02x(?)
SetIsSubsetOf 2771 2711 -2.2% 1.02x(?)
StringHasPrefixUnicode 17511 17237 -1.6% 1.02x
135 6512724 6439018 -1.1% 1.01x
RecursiveOwnedParameter 10954 10841 -1.0% 1.01x
StringWithCString 149812 148149 -1.1% 1.01x
RangeAssignment 27438 27207 -0.8% 1.01x(?)
SuperChars 255119 252916 -0.9% 1.01x(?)
ArrayLiteral 1201 1190 -0.9% 1.01x
PopFrontArrayGeneric 10024 9971 -0.5% 1.01x(?)
PolymorphicCalls 1114 1098 -1.4% 1.01x
SortStringsUnicode 10299 10242 -0.6% 1.01x
ObjectiveCBridgeStubDataAppend 3712 3670 -1.1% 1.01x(?)
HashTest 5417 5388 -0.5% 1.01x(?)
LinkedList 27769 27595 -0.6% 1.01x
ObjectiveCBridgeFromNSSetAnyObjectForced 9309 9230 -0.8% 1.01x(?)
ArrayValueProp3 3035 3002 -1.1% 1.01x
ArrayValueProp4 2978 2945 -1.1% 1.01x
SevenBoom 1522 1512 -0.7% 1.01x(?)
ArraySubscript 5730 5736 +0.1% 1.00x(?)
ObjectiveCBridgeToNSString 1100 1102 +0.2% 1.00x(?)
MonteCarloPi 53410 53419 +0.0% 1.00x(?)
ObjectiveCBridgeStubToNSString 1333 1335 +0.1% 1.00x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 312614 313487 +0.3% 1.00x(?)
AnyHashableWithAClass 78684 78750 +0.1% 1.00x(?)
ClassArrayGetter 1269 1271 +0.2% 1.00x(?)
Array2D 815257 816370 +0.1% 1.00x
ObjectiveCBridgeStubFromNSDateRef 4342 4341 -0.0% 1.00x(?)
OpenClose 495 493 -0.4% 1.00x
Prims 14014 13973 -0.3% 1.00x(?)
SortLettersInPlace 2567 2557 -0.4% 1.00x(?)
ByteSwap 10 10 +0.0% 1.00x
XorLoop 20143 20168 +0.1% 1.00x
Integrate 375 375 +0.0% 1.00x
ObjectiveCBridgeStubFromNSStringRef 194 194 +0.0% 1.00x
ProtocolDispatch 6894 6890 -0.1% 1.00x
ProtocolDispatch2 457 457 +0.0% 1.00x
Walsh 14181 14178 -0.0% 1.00x(?)
Join 1455 1459 +0.3% 1.00x
ArrayOfRef 9279 9270 -0.1% 1.00x(?)
ArrayAppend 3858 3845 -0.3% 1.00x(?)
ObjectiveCBridgeStubDateMutation 631 631 +0.0% 1.00x
NSError 648 647 -0.1% 1.00x(?)
StringEqualPointerComparison 11121 11086 -0.3% 1.00x
ObjectiveCBridgeStubToNSStringRef 178 178 +0.0% 1.00x
MapReduce 47090 47122 +0.1% 1.00x(?)
IterateData 10587 10566 -0.2% 1.00x(?)
Hanoi 20016 19946 -0.3% 1.00x(?)
ArrayOfGenericPOD 4099 4092 -0.2% 1.00x
UTF8Decode 43299 43367 +0.2% 1.00x(?)
ObjectiveCBridgeStubURLAppendPath 365104 366855 +0.5% 1.00x(?)
GlobalClass 0 0 +0.0% 1.00x
StringBuilder 2844 2843 -0.0% 1.00x(?)
ArrayInClass 3973 3972 -0.0% 1.00x(?)
ArrayOfGenericRef 9929 9974 +0.5% 1.00x
Phonebook 62168 62085 -0.1% 1.00x(?)
ObjectiveCBridgeStubDateAccess 1146 1146 +0.0% 1.00x
Sim2DArray 14730 14716 -0.1% 1.00x(?)
MonteCarloE 109946 109853 -0.1% 1.00x(?)
StringHasSuffixUnicode 75142 75002 -0.2% 1.00x
ObjectiveCBridgeToNSSet 24528 24484 -0.2% 1.00x(?)
NSStringConversion 3080 3084 +0.1% 1.00x(?)
ArrayAppendReserved 3594 3594 +0.0% 1.00x
ArrayOfPOD 2430 2432 +0.1% 1.00x(?)
Chars 5942 5938 -0.1% 1.00x
DeadArray 118803 118656 -0.1% 1.00x(?)
BitCount 131 131 +0.0% 1.00x
AngryPhonebook 3028 3024 -0.1% 1.00x(?)
ArrayValueProp 2497 2492 -0.2% 1.00x(?)
ObjectiveCBridgeStubFromArrayOfNSString 77717 77497 -0.3% 1.00x(?)
RC4 9618 9614 -0.0% 1.00x(?)
Memset 21131 21134 +0.0% 1.00x(?)
ArrayValueProp2 3041 3029 -0.4% 1.00x(?)
ObjectiveCBridgeStubFromNSDate 4287 4283 -0.1% 1.00x(?)
ErrorHandling 3844 3869 +0.7% 0.99x(?)
ObjectiveCBridgeStubFromNSString 979 988 +0.9% 0.99x
ObjectiveCBridgeStubURLAppendPathRef 373760 376505 +0.7% 0.99x(?)
ObjectiveCBridgeToNSArray 30432 30591 +0.5% 0.99x(?)
ObjectiveCBridgeStubToNSDateRef 3311 3337 +0.8% 0.99x(?)
CaptureProp 129512 131100 +1.2% 0.99x(?)
ObjectiveCBridgeStubNSDateRefAccess 1267 1277 +0.8% 0.99x(?)
ObjectiveCBridgeStubNSDataAppend 3082 3119 +1.2% 0.99x(?)
SortStrings 2837 2884 +1.7% 0.98x
StaticArray 38729 39457 +1.9% 0.98x(?)
ObjectiveCBridgeStubNSDateMutationRef 14383 14744 +2.5% 0.98x
ObjectiveCBridgeFromNSSetAnyObject 337520 346450 +2.6% 0.97x(?)
PopFrontArray 24349 25571 +5.0% 0.95x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 105862 110963 +4.8% 0.95x(?)
**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: 16 GB

Those conditions should not fail with any user code. They just check the internal implementation of the stdlib.
This removes some runtime checks in the generated code with the optimized library.
…y/Set is never negative.

This removes some runtime checks.
…r-of-2 ranges.

This function is only used for Set and Dictionary and there the range (which is the capacity) is always a power of 2.
If the Key is a class, then FunctionSignatureOpts cannot convert it to a @guaranteed parameter.
Using the new EpilogueARCAnalysis in FunctionSignatureOpts should fix that.
@eeckstein
Copy link
Contributor Author

@moiseev, @dabrahams, @gankro: here is a new version

@eeckstein
Copy link
Contributor Author

@swift-ci Please smoke test

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci Please smoke test

@shahmishal
Copy link
Member

Re-testing due to failure in ToT.
@swift-ci please smoke test

@eeckstein eeckstein merged commit ddbfe2b into swiftlang:master Sep 21, 2016
@eeckstein eeckstein deleted the dict-set branch September 21, 2016 03:55
MaxDesiatov pushed a commit that referenced this pull request Sep 7, 2023
[pull] swiftwasm from main
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.

7 participants