Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stdlib] Make various free functions mutating an _ArrayBufferProtocol into extensions #5483

Merged
merged 12 commits into from
Oct 27, 2016

Conversation

airspeedswift
Copy link
Member

@airspeedswift airspeedswift commented Oct 26, 2016

This started from the fairly innocent FIXME(ABI)#14 : add argument labels to conform to naming convention guidelines. but then evolved into changing a number of generic functions that took an inout conforming to _ArrayBufferProtocol to be mutating methods on the protocol instead.

Also added a missing endIndex: Int declaration to the protocol, which was what appears to have been forcing the need to keep adding where Index == Int in various places, and did some other cleanup to make replace(subRange:) look more like RangeReplaceableCollection's replaceSubrange.

This seems to leave us within striking distance of making _ArrayBufferProtocol conform to RangeReplaceableCollection, which would tidy up a number of functions that are duplicating functionality that exists there. But that may have performance impact so putting this in first.

@airspeedswift
Copy link
Member Author

@swift-ci please test

@@ -1823,141 +1819,141 @@ public func += <

//===--- generic helpers --------------------------------------------------===//
Copy link
Contributor

Choose a reason for hiding this comment

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

They are not really generic anymore... in a sense.

@moiseev
Copy link
Contributor

moiseev commented Oct 26, 2016

@swift-ci Please benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Optimized (O)

Regression (1)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
StaticArray 2674 2853 +6.7% 0.94x(?)

Improvement (0)

No Changes (137)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
Calculator 30 29 -3.3% 1.03x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 143049 138553 -3.1% 1.03x(?)
ObjectiveCBridgeToNSDictionary 16542 16106 -2.6% 1.03x(?)
137 3089343 3037158 -1.7% 1.02x
ObjectiveCBridgeFromNSSetAnyObject 98458 96633 -1.9% 1.02x(?)
Dictionary2 2056 2016 -1.9% 1.02x(?)
SetIsSubsetOf 480 471 -1.9% 1.02x(?)
ArrayOfPOD 176 172 -2.3% 1.02x(?)
DeadArray 186 182 -2.1% 1.02x(?)
DictionarySwap 631 627 -0.6% 1.01x(?)
ObjectAllocation 154 153 -0.7% 1.01x(?)
Dictionary3 510 507 -0.6% 1.01x(?)
ObjectiveCBridgeToNSArray 30863 30422 -1.4% 1.01x(?)
PopFrontArrayGeneric 1121 1114 -0.6% 1.01x(?)
MapReduce 351 348 -0.8% 1.01x(?)
DictionaryLiteral 2775 2741 -1.2% 1.01x(?)
ObjectiveCBridgeStubURLAppendPath 243749 241462 -0.9% 1.01x(?)
Dictionary 752 743 -1.2% 1.01x(?)
ObjectiveCBridgeStubToArrayOfNSString 30114 29694 -1.4% 1.01x(?)
RGBHistogram 2840 2820 -0.7% 1.01x(?)
ArrayAppendReserved 521 518 -0.6% 1.01x(?)
Chars 643 636 -1.1% 1.01x(?)
ObjectiveCBridgeToNSString 1080 1078 -0.2% 1.00x(?)
RecursiveOwnedParameter 1828 1830 +0.1% 1.00x(?)
ObjectiveCBridgeStubToNSString 1257 1253 -0.3% 1.00x(?)
ClassArrayGetter 13 13 +0.0% 1.00x
Histogram 637 637 +0.0% 1.00x
ArrayAppendArray 257 256 -0.4% 1.00x(?)
DictionaryBridge 3939 3933 -0.1% 1.00x(?)
ObjectiveCBridgeStubFromNSDateRef 3651 3666 +0.4% 1.00x(?)
ArrayOfGenericPOD 213 214 +0.5% 1.00x(?)
ObjectiveCBridgeFromNSString 1828 1826 -0.1% 1.00x(?)
Dictionary3OfObjects 858 858 +0.0% 1.00x
StrComplexWalk 2893 2883 -0.3% 1.00x(?)
ByteSwap 0 0 +0.0% 1.00x
SuperChars 208104 208507 +0.2% 1.00x(?)
Join 453 454 +0.2% 1.00x(?)
ProtocolDispatch 3039 3040 +0.0% 1.00x(?)
TypeFlood 0 0 +0.0% 1.00x
ErrorHandling 2956 2961 +0.2% 1.00x(?)
ArrayOfRef 3526 3526 +0.0% 1.00x
ObjectiveCBridgeStubDateMutation 269 268 -0.4% 1.00x(?)
NSError 325 324 -0.3% 1.00x(?)
DictionaryOfObjects 2299 2291 -0.3% 1.00x(?)
ObjectiveCBridgeStubToNSDateRef 3213 3215 +0.1% 1.00x(?)
PopFrontUnsafePointer 8893 8880 -0.1% 1.00x(?)
PolymorphicCalls 20 20 +0.0% 1.00x
RC4 162 162 +0.0% 1.00x
OpenClose 53 53 +0.0% 1.00x
SortStringsUnicode 8312 8352 +0.5% 1.00x(?)
SetIntersect 1038 1043 +0.5% 1.00x(?)
ObjectiveCBridgeStubDataAppend 3007 3016 +0.3% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectToString 147085 147381 +0.2% 1.00x(?)
ObjectiveCBridgeStubNSDateRefAccess 341 342 +0.3% 1.00x(?)
ArrayInClass 64 64 +0.0% 1.00x
ObjectiveCBridgeStubDateAccess 182 182 +0.0% 1.00x
Sim2DArray 286 285 -0.3% 1.00x(?)
MonteCarloPi 42642 42496 -0.3% 1.00x(?)
MonteCarloE 9959 9952 -0.1% 1.00x(?)
StringHasSuffixUnicode 64069 63808 -0.4% 1.00x(?)
HashTest 1753 1760 +0.4% 1.00x(?)
SetIsSubsetOf_OfObjects 493 493 +0.0% 1.00x
ArrayAppend 755 755 +0.0% 1.00x
DictionaryRemove 4622 4639 +0.4% 1.00x(?)
LinkedList 6804 6805 +0.0% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 110542 110845 +0.3% 1.00x(?)
RGBHistogramOfObjects 21360 21418 +0.3% 1.00x(?)
NSStringConversion 820 817 -0.4% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectForced 4604 4607 +0.1% 1.00x(?)
StringBuilder 1325 1329 +0.3% 1.00x(?)
ArrayValueProp2 5 5 +0.0% 1.00x
BitCount 1 1 +0.0% 1.00x
AnyHashableWithAClass 65371 65139 -0.3% 1.00x(?)
SevenBoom 1363 1366 +0.2% 1.00x(?)
StringWalk 5592 5601 +0.2% 1.00x(?)
ArrayValueProp 5 5 +0.0% 1.00x
GlobalClass 0 0 +0.0% 1.00x
Memset 222 222 +0.0% 1.00x
Dictionary2OfObjects 3392 3403 +0.3% 1.00x(?)
ArrayValueProp4 5 5 +0.0% 1.00x
ArrayValueProp3 5 5 +0.0% 1.00x
DictionarySwapOfObjects 6660 6734 +1.1% 0.99x(?)
StackPromo 20452 20672 +1.1% 0.99x(?)
ObjectiveCBridgeFromNSDictionaryAnyObject 206189 208429 +1.1% 0.99x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 215022 216819 +0.8% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToString 119668 120935 +1.1% 0.99x(?)
Array2D 2059 2070 +0.5% 0.99x(?)
SortStrings 1761 1783 +1.2% 0.99x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 5274 5315 +0.8% 0.99x(?)
StringWithCString 148027 149977 +1.3% 0.99x(?)
SortLettersInPlace 944 949 +0.5% 0.99x(?)
XorLoop 375 380 +1.3% 0.99x(?)
Integrate 241 244 +1.2% 0.99x(?)
ObjectiveCBridgeStubFromNSStringRef 132 134 +1.5% 0.99x(?)
ArrayLiteral 1188 1203 +1.3% 0.99x(?)
SetIntersect_OfObjects 2169 2180 +0.5% 0.99x(?)
ObjectiveCBridgeStubURLAppendPathRef 237212 240297 +1.3% 0.99x(?)
ObjectiveCBridgeToNSSet 16055 16239 +1.1% 0.99x(?)
AngryPhonebook 2843 2868 +0.9% 0.99x(?)
IterateData 2492 2515 +0.9% 0.99x(?)
UTF8Decode 281 283 +0.7% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObject 76830 77675 +1.1% 0.99x(?)
ArrayOfGenericRef 3547 3565 +0.5% 0.99x(?)
StringHasSuffix 713 719 +0.8% 0.99x(?)
Phonebook 6952 6999 +0.7% 0.99x(?)
SetUnion 2935 2964 +1.0% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 91829 93188 +1.5% 0.99x(?)
TwoSum 1586 1596 +0.6% 0.99x(?)
ObjectiveCBridgeStubNSDataAppend 2457 2485 +1.1% 0.99x(?)
ObjectiveCBridgeStubFromNSDate 3591 3626 +1.0% 0.99x(?)
ArraySubscript 1376 1399 +1.7% 0.98x(?)
ObjectiveCBridgeFromNSStringForced 2704 2757 +2.0% 0.98x(?)
PopFrontArray 1096 1115 +1.7% 0.98x(?)
StringInterpolation 11068 11253 +1.7% 0.98x(?)
ObjectiveCBridgeStubFromNSString 763 775 +1.6% 0.98x(?)
ProtocolDispatch2 159 163 +2.5% 0.98x(?)
Walsh 323 329 +1.9% 0.98x(?)
StringHasPrefix 595 608 +2.2% 0.98x(?)
ObjectiveCBridgeStubToNSStringRef 118 121 +2.5% 0.98x(?)
DictionaryRemoveOfObjects 19379 19723 +1.8% 0.98x(?)
SetExclusiveOr 2601 2648 +1.8% 0.98x(?)
NSDictionaryCastToSwift 6844 7012 +2.5% 0.98x(?)
SetExclusiveOr_OfObjects 7561 7729 +2.2% 0.98x(?)
StringHasPrefixUnicode 13939 14190 +1.8% 0.98x(?)
ArrayAppendSequence 518 527 +1.7% 0.98x(?)
ObjectiveCBridgeStubFromArrayOfNSString 59250 60227 +1.6% 0.98x(?)
ObjectiveCBridgeFromNSArrayAnyObjectForced 6280 6442 +2.6% 0.97x(?)
Prims 715 734 +2.7% 0.97x(?)
RangeAssignment 277 287 +3.6% 0.97x(?)
ObjectiveCBridgeStubToNSDate 13118 13512 +3.0% 0.97x(?)
StringEqualPointerComparison 7327 7528 +2.7% 0.97x(?)
NopDeinit 36610 38028 +3.9% 0.96x
StrToInt 4968 5192 +4.5% 0.96x(?)
SetUnion_OfObjects 6378 6623 +3.8% 0.96x(?)
CaptureProp 4394 4604 +4.8% 0.95x(?)
Hanoi 3174 3334 +5.0% 0.95x
ObjectiveCBridgeStubNSDateMutationRef 11614 12243 +5.4% 0.95x(?)
**Unoptimized (Onone)**

Regression (4)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
ByteSwap 9 10 +11.1% 0.90x
ObjectiveCBridgeFromNSArrayAnyObjectForced 10515 11135 +5.9% 0.94x(?)
ArrayAppend 3446 3653 +6.0% 0.94x
ArrayAppendReserved 3237 3431 +6.0% 0.94x

Improvement (2)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
MonteCarloE 115973 108592 -6.4% 1.07x
RangeAssignment 27621 13338 -51.7% 2.07x

No Changes (132)

TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
ObjectiveCBridgeStubDateMutation 563 534 -5.2% 1.05x
ArrayOfGenericPOD 3630 3502 -3.5% 1.04x(?)
TypeFlood 188 180 -4.3% 1.04x(?)
StringWalk 23539 22559 -4.2% 1.04x(?)
StringWithCString 154751 150434 -2.8% 1.03x(?)
ObjectiveCBridgeStubToNSDate 14301 13887 -2.9% 1.03x(?)
CaptureProp 121310 117853 -2.9% 1.03x
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 150758 146518 -2.8% 1.03x(?)
ObjectiveCBridgeStubDateAccess 1161 1130 -2.7% 1.03x
StringHasPrefixUnicode 15868 15471 -2.5% 1.03x
ObjectiveCBridgeFromNSSetAnyObjectToString 163994 159826 -2.5% 1.03x(?)
StringHasPrefix 1671 1635 -2.1% 1.02x(?)
StaticArray 36570 35916 -1.8% 1.02x(?)
ObjectiveCBridgeToNSString 1134 1124 -0.9% 1.01x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToString 127369 126381 -0.8% 1.01x(?)
Histogram 11764 11683 -0.7% 1.01x(?)
ObjectiveCBridgeStubFromNSDateRef 4215 4172 -1.0% 1.01x
SortLettersInPlace 2583 2552 -1.2% 1.01x(?)
ObjectiveCBridgeFromNSString 5358 5286 -1.3% 1.01x(?)
ObjectiveCBridgeStubFromNSStringRef 167 166 -0.6% 1.01x(?)
ObjectiveCBridgeToNSArray 31431 31172 -0.8% 1.01x(?)
PopFrontUnsafePointer 247829 246545 -0.5% 1.01x(?)
StringEqualPointerComparison 9917 9774 -1.4% 1.01x(?)
PolymorphicCalls 1196 1182 -1.2% 1.01x(?)
AngryPhonebook 3015 2997 -0.6% 1.01x(?)
OpenClose 457 451 -1.3% 1.01x(?)
ObjectiveCBridgeStubToArrayOfNSString 30757 30393 -1.2% 1.01x(?)
SetExclusiveOr_OfObjects 45953 45653 -0.7% 1.01x(?)
ObjectiveCBridgeToNSDictionary 16817 16588 -1.4% 1.01x(?)
ObjectiveCBridgeToNSSet 16512 16308 -1.2% 1.01x(?)
DictionaryRemove 17507 17381 -0.7% 1.01x(?)
StrToInt 5985 5913 -1.2% 1.01x
ArrayValueProp 2627 2612 -0.6% 1.01x(?)
ObjectiveCBridgeStubFromArrayOfNSString 61819 61367 -0.7% 1.01x(?)
Dictionary2OfObjects 6298 6265 -0.5% 1.01x(?)
ArraySubscript 5618 5617 -0.0% 1.00x(?)
137 5634249 5607882 -0.5% 1.00x
RecursiveOwnedParameter 10276 10314 +0.4% 1.00x(?)
ClassArrayGetter 1304 1304 +0.0% 1.00x
SortStrings 2779 2774 -0.2% 1.00x(?)
Prims 13496 13509 +0.1% 1.00x(?)
ObjectiveCBridgeFromNSDictionaryAnyObject 215332 216268 +0.4% 1.00x(?)
Dictionary3OfObjects 2262 2261 -0.0% 1.00x(?)
SuperChars 259567 258869 -0.3% 1.00x(?)
XorLoop 19378 19395 +0.1% 1.00x(?)
ObjectiveCBridgeStubToNSString 1338 1338 +0.0% 1.00x
ProtocolDispatch 6407 6418 +0.2% 1.00x(?)
StringHasSuffixUnicode 65939 66060 +0.2% 1.00x(?)
ArrayLiteral 1221 1215 -0.5% 1.00x(?)
ProtocolDispatch2 451 452 +0.2% 1.00x(?)
HashTest 5383 5410 +0.5% 1.00x(?)
Dictionary3 1602 1609 +0.4% 1.00x(?)
Dictionary2 4430 4452 +0.5% 1.00x(?)
SetIntersect_OfObjects 13976 13946 -0.2% 1.00x(?)
Join 1456 1455 -0.1% 1.00x(?)
ArrayOfRef 9382 9397 +0.2% 1.00x(?)
ObjectiveCBridgeStubURLAppendPathRef 245412 245510 +0.0% 1.00x(?)
PopFrontArrayGeneric 9699 9693 -0.1% 1.00x(?)
Calculator 1033 1030 -0.3% 1.00x
MapReduce 43135 43292 +0.4% 1.00x(?)
IterateData 10763 10787 +0.2% 1.00x(?)
DictionaryLiteral 16819 16874 +0.3% 1.00x(?)
Hanoi 20490 20426 -0.3% 1.00x(?)
UTF8Decode 42189 42184 -0.0% 1.00x(?)
SetIsSubsetOf 2449 2445 -0.2% 1.00x(?)
NopDeinit 64610 64677 +0.1% 1.00x(?)
SetIntersect 15277 15246 -0.2% 1.00x(?)
SetExclusiveOr 30269 30313 +0.1% 1.00x(?)
NSDictionaryCastToSwift 8339 8306 -0.4% 1.00x(?)
RGBHistogramOfObjects 93397 93352 -0.1% 1.00x(?)
ObjectiveCBridgeStubNSDateRefAccess 1271 1266 -0.4% 1.00x(?)
StringBuilder 2818 2813 -0.2% 1.00x(?)
ArrayOfGenericRef 10035 10062 +0.3% 1.00x(?)
SetUnion_OfObjects 33288 33344 +0.2% 1.00x(?)
Walsh 12802 12810 +0.1% 1.00x(?)
SetIsSubsetOf_OfObjects 2220 2219 -0.1% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 122830 122838 +0.0% 1.00x(?)
ObjectiveCBridgeFromNSSetAnyObjectForced 7687 7710 +0.3% 1.00x(?)
SetUnion 18493 18526 +0.2% 1.00x
Chars 5147 5146 -0.0% 1.00x(?)
DeadArray 121200 121330 +0.1% 1.00x(?)
ArrayValueProp2 3129 3140 +0.3% 1.00x(?)
BitCount 106 106 +0.0% 1.00x
AnyHashableWithAClass 79855 79928 +0.1% 1.00x(?)
SevenBoom 1487 1492 +0.3% 1.00x(?)
GlobalClass 0 0 +0.0% 1.00x
Memset 19811 19880 +0.3% 1.00x(?)
TwoSum 6564 6574 +0.1% 1.00x(?)
ObjectiveCBridgeStubNSDataAppend 2908 2894 -0.5% 1.00x(?)
DictionarySwapOfObjects 21020 21312 +1.4% 0.99x(?)
Integrate 375 380 +1.3% 0.99x
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 224201 227324 +1.4% 0.99x(?)
MonteCarloPi 51174 51903 +1.4% 0.99x(?)
DictionarySwap 7511 7618 +1.4% 0.99x
ErrorHandling 3822 3854 +0.8% 0.99x(?)
ObjectiveCBridgeStubFromNSString 840 849 +1.1% 0.99x(?)
ObjectiveCBridgeFromNSSetAnyObject 103636 104987 +1.3% 0.99x(?)
StrComplexWalk 8196 8302 +1.3% 0.99x(?)
DictionaryOfObjects 4873 4911 +0.8% 0.99x(?)
ObjectiveCBridgeStubToNSDateRef 3301 3325 +0.7% 0.99x(?)
ObjectiveCBridgeStubToNSStringRef 157 158 +0.6% 0.99x(?)
DictionaryRemoveOfObjects 46865 47364 +1.1% 0.99x(?)
SortStringsUnicode 9540 9621 +0.8% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObject 78696 79838 +1.4% 0.99x(?)
ObjectiveCBridgeStubDataAppend 3419 3455 +1.1% 0.99x(?)
Sim2DArray 14254 14331 +0.5% 0.99x(?)
LinkedList 26059 26312 +1.0% 0.99x(?)
ArrayValueProp3 3173 3200 +0.8% 0.99x(?)
StackPromo 128455 130819 +1.8% 0.98x(?)
DictionaryBridge 3949 4019 +1.8% 0.98x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 7958 8115 +2.0% 0.98x(?)
StringInterpolation 15776 16048 +1.7% 0.98x(?)
ObjectAllocation 572 582 +1.8% 0.98x(?)
StringHasSuffix 1746 1790 +2.5% 0.98x(?)
RGBHistogram 43042 44125 +2.5% 0.98x(?)
ArrayAppendSequence 53910 54837 +1.7% 0.98x(?)
ArrayOfPOD 2406 2462 +2.3% 0.98x
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 93827 95520 +1.8% 0.98x(?)
ArrayValueProp4 3040 3090 +1.6% 0.98x(?)
ObjectiveCBridgeStubFromNSDate 3852 3937 +2.2% 0.98x
PopFrontArray 24357 25011 +2.7% 0.97x(?)
Array2D 787481 811338 +3.0% 0.97x(?)
ArrayAppendArray 292 300 +2.7% 0.97x(?)
ObjectiveCBridgeFromNSStringForced 3136 3219 +2.6% 0.97x(?)
Dictionary 2139 2209 +3.3% 0.97x(?)
ArrayInClass 3835 3951 +3.0% 0.97x(?)
RC4 9085 9354 +3.0% 0.97x(?)
NSStringConversion 3115 3205 +2.9% 0.97x(?)
ObjectiveCBridgeStubNSDateMutationRef 14053 14430 +2.7% 0.97x(?)
NSError 682 714 +4.7% 0.96x(?)
Phonebook 63077 65874 +4.4% 0.96x(?)
ObjectiveCBridgeStubURLAppendPath 235889 247714 +5.0% 0.95x(?)
**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

@airspeedswift
Copy link
Member Author

Benchmarks look ok to me.

@slavapestov
Copy link
Contributor

Cool!

@airspeedswift airspeedswift merged commit fbed646 into swiftlang:master Oct 27, 2016
@airspeedswift airspeedswift deleted the buffer-protocol branch October 27, 2016 18:38
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.

4 participants