Skip to content

Switch MetadataCache to use a global slab allocator. #7109

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 1 commit into from
Jan 28, 2017

Conversation

rjmccall
Copy link
Contributor

This seems to more than fix a performance regression that we
detected on a metadata-allocation microbenchmark.

A few months ago, I improved the metadata cache representation
and changed the metadata allocation scheme to primarily use malloc.
Previously, we'd been using malloc in the concurrent tree data
structure but a per-cache slab allocator for the metadata itself.
At the time, I was concerned about the overhead of per-cache
allocators, since many metadata patterns see only a small number
of instantiations. That's still an important factor, so in the
new scheme we're using a global allocator; but instead of using
malloc for individual allocations, we're using a slab allocator,
which should have better peak, single-thread performance, at the
cost of not easily supporting deallocation. Deallocation is
only used for metadata when there's contention on the cache, and
specifically only when there's contention for the same key, so
leaking a little isn't the worst thing in the world.

The initial slab is a 64K globally-allocated buffer.
Successive slabs are 16K and allocated with malloc.

Resolves rdar://28189496.

@rjmccall
Copy link
Contributor Author

@swift-ci Please smoke test.

@rjmccall
Copy link
Contributor Author

@swift-ci Please benchmark.

@rjmccall
Copy link
Contributor Author

Hmm, GCC doesn't emit this with cmpxchg16b. That's going to require some investigation.

@gparker42
Copy link
Contributor

We should chain the pools together (reserve the first or last word for the link to the next or something). Otherwise heap analysis tools will complain about leaks once there are three pools allocated.

@gparker42
Copy link
Contributor

Do you have any measurements of pool space occupied by any current apps?

@swift-ci
Copy link
Contributor

Build comment file:

Optimized (O)

Regression (0)
Improvement (0)
No Changes (159)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
ObjectiveCBridgeStubNSDateMutationRef 12067 11638 -3.6% 1.04x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 5633 5485 -2.6% 1.03x(?)
Prims 762 749 -1.7% 1.02x(?)
StringHasPrefix 747 729 -2.4% 1.02x(?)
SuperChars 216034 212734 -1.5% 1.02x(?)
ObjectiveCBridgeStubURLAppendPath 245196 240859 -1.8% 1.02x(?)
AnyHashableWithAClass 64568 63888 -1.1% 1.01x
StaticArray 127 126 -0.8% 1.01x
SetIntersect_OfObjects 1457 1443 -1.0% 1.01x(?)
RC4 157 156 -0.6% 1.01x
ArrayOfGenericRef 3985 3951 -0.8% 1.01x(?)
SetExclusiveOr_OfObjects 7442 7400 -0.6% 1.01x(?)
StringHasPrefixUnicode 13995 13877 -0.8% 1.01x
NSStringConversion 731 723 -1.1% 1.01x(?)
ObjectiveCBridgeFromNSSetAnyObjectForced 4570 4532 -0.8% 1.01x(?)
SetUnion 2280 2263 -0.8% 1.01x(?)
TwoSum 1341 1332 -0.7% 1.01x(?)
ObjectiveCBridgeStubFromNSDate 3922 3871 -1.3% 1.01x(?)
ArraySubscript 1434 1437 +0.2% 1.00x(?)
ObjectiveCBridgeToNSString 1274 1274 +0.0% 1.00x
DictionarySwapOfObjects 7005 7026 +0.3% 1.00x(?)
RecursiveOwnedParameter 1930 1929 -0.1% 1.00x(?)
Integrate 237 237 +0.0% 1.00x
ClassArrayGetter 13 13 +0.0% 1.00x
Histogram 289 289 +0.0% 1.00x
SortStrings 1633 1628 -0.3% 1.00x(?)
ObjectiveCBridgeStubFromNSDateRef 3703 3703 +0.0% 1.00x
MonteCarloPi 44856 44853 -0.0% 1.00x(?)
StringWithCString 154573 154625 +0.0% 1.00x(?)
ObjectiveCBridgeFromNSArrayAnyObjectForced 6093 6110 +0.3% 1.00x(?)
ObjectiveCBridgeFromNSStringForced 2307 2314 +0.3% 1.00x(?)
SortLettersInPlace 1057 1060 +0.3% 1.00x(?)
DictionarySwap 411 411 +0.0% 1.00x
ArrayAppendToFromGeneric 596 597 +0.2% 1.00x(?)
PopFrontArray 1088 1088 +0.0% 1.00x
Dictionary3OfObjects 920 916 -0.4% 1.00x(?)
RangeAssignment 295 294 -0.3% 1.00x(?)
ByteSwap 0 0 +0.0% 1.00x
ArrayAppendGenericStructs 1228 1227 -0.1% 1.00x(?)
ArrayAppendLazyMap 914 916 +0.2% 1.00x(?)
ArrayPlusEqualFiveElementCollection 59174 59083 -0.1% 1.00x(?)
ObjectiveCBridgeStubToNSDate 14215 14250 +0.2% 1.00x(?)
XorLoop 352 352 +0.0% 1.00x
StringInterpolation 11069 11017 -0.5% 1.00x(?)
ObserverClosure 2118 2125 +0.3% 1.00x(?)
CharacterLiteralsSmall 812 812 +0.0% 1.00x
ObjectiveCBridgeStubToNSString 1494 1493 -0.1% 1.00x(?)
ArrayPlusEqualSingleElementCollection 56335 56215 -0.2% 1.00x(?)
ArrayAppendStrings 12108 12090 -0.1% 1.00x(?)
ObjectiveCBridgeStubFromNSStringRef 200 200 +0.0% 1.00x
ObjectiveCBridgeStubFromNSString 922 922 +0.0% 1.00x
ProtocolDispatch 3030 3030 +0.0% 1.00x
ObjectAllocation 174 174 +0.0% 1.00x
TypeFlood 0 0 +0.0% 1.00x
SortSortedStrings 794 794 +0.0% 1.00x
ObjectiveCBridgeFromNSSetAnyObject 70302 70187 -0.2% 1.00x(?)
AngryPhonebook 3232 3225 -0.2% 1.00x(?)
ProtocolDispatch2 159 159 +0.0% 1.00x
CharacterLiteralsLarge 12286 12288 +0.0% 1.00x(?)
Walsh 323 324 +0.3% 1.00x(?)
Dictionary3 531 531 +0.0% 1.00x
Dictionary2 2090 2088 -0.1% 1.00x(?)
Join 487 488 +0.2% 1.00x(?)
ArrayOfRef 3863 3847 -0.4% 1.00x(?)
ObjectiveCBridgeStubURLAppendPathRef 242532 242896 +0.1% 1.00x(?)
ArrayPlusEqualArrayOfInt 597 597 +0.0% 1.00x
OpenClose 54 54 +0.0% 1.00x
ObjectiveCBridgeToNSArray 32033 32094 +0.2% 1.00x(?)
NSError 351 350 -0.3% 1.00x(?)
DictionaryOfObjects 2472 2467 -0.2% 1.00x(?)
ObjectiveCBridgeStubToNSDateRef 3386 3378 -0.2% 1.00x(?)
PopFrontArrayGeneric 1098 1098 +0.0% 1.00x
PopFrontUnsafePointer 8949 8953 +0.0% 1.00x(?)
StringEqualPointerComparison 7274 7274 +0.0% 1.00x
CaptureProp 3962 3952 -0.2% 1.00x(?)
PolymorphicCalls 21 21 +0.0% 1.00x
ArrayAppendReserved 739 739 +0.0% 1.00x
ObjectiveCBridgeStubToNSStringRef 132 132 +0.0% 1.00x
Calculator 31 31 +0.0% 1.00x
ArrayAppendFromGeneric 597 597 +0.0% 1.00x
MapReduce 341 341 +0.0% 1.00x
ObjectiveCBridgeStubDateMutation 272 272 +0.0% 1.00x
IterateData 2517 2517 +0.0% 1.00x
Hanoi 3175 3172 -0.1% 1.00x(?)
ArrayOfGenericPOD 219 219 +0.0% 1.00x
DictionaryRemoveOfObjects 21357 21302 -0.3% 1.00x(?)
UTF8Decode 282 282 +0.0% 1.00x
SetIsSubsetOf 242 242 +0.0% 1.00x
NopDeinit 22633 22707 +0.3% 1.00x(?)
ObjectiveCBridgeStubToArrayOfNSString 31537 31465 -0.2% 1.00x(?)
ObjectiveCBridgeFromNSArrayAnyObject 66566 66699 +0.2% 1.00x(?)
SetIntersect 347 348 +0.3% 1.00x(?)
SetExclusiveOr 2858 2854 -0.1% 1.00x(?)
ArrayAppendOptionals 1228 1224 -0.3% 1.00x(?)
StrToInt 5014 5015 +0.0% 1.00x(?)
ArrayInClass 61 61 +0.0% 1.00x
Phonebook 7078 7085 +0.1% 1.00x(?)
ObjectiveCBridgeStubDateAccess 181 181 +0.0% 1.00x
Sim2DArray 276 276 +0.0% 1.00x
ArrayAppendRepeatCol 755 756 +0.1% 1.00x(?)
ObjectiveCBridgeToNSDictionary 61532 61696 +0.3% 1.00x(?)
MonteCarloE 10459 10456 -0.0% 1.00x(?)
SetUnion_OfObjects 6208 6194 -0.2% 1.00x(?)
ReversedBidirectional 49562 49592 +0.1% 1.00x(?)
StringHasSuffixUnicode 60503 60490 -0.0% 1.00x(?)
ArrayAppendToGeneric 597 596 -0.2% 1.00x(?)
HashTest 1815 1813 -0.1% 1.00x(?)
SetIsSubsetOf_OfObjects 309 309 +0.0% 1.00x
ArrayAppend 982 982 +0.0% 1.00x
LinkedList 7207 7227 +0.3% 1.00x
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 69598 69516 -0.1% 1.00x(?)
RGBHistogramOfObjects 22105 22154 +0.2% 1.00x(?)
RGBHistogram 2254 2263 +0.4% 1.00x(?)
ArrayAppendSequence 975 975 +0.0% 1.00x
ArrayAppendArrayOfInt 597 597 +0.0% 1.00x
ArrayOfPOD 165 165 +0.0% 1.00x
Chars 610 610 +0.0% 1.00x
ReversedArray 49 49 +0.0% 1.00x
StringBuilder 1412 1412 +0.0% 1.00x
ObjectiveCBridgeStubNSDateRefAccess 346 345 -0.3% 1.00x(?)
DeadArray 181 181 +0.0% 1.00x
ObjectiveCBridgeStubNSDataAppend 2276 2285 +0.4% 1.00x(?)
BitCount 1 1 +0.0% 1.00x
ArrayLiteral 1383 1387 +0.3% 1.00x(?)
SevenBoom 1478 1475 -0.2% 1.00x(?)
StringWalk 5955 5955 +0.0% 1.00x
ArrayValueProp 6 6 +0.0% 1.00x
ObjectiveCBridgeStubFromArrayOfNSString 59847 59991 +0.2% 1.00x(?)
StringHasSuffix 798 798 +0.0% 1.00x
GlobalClass 0 0 +0.0% 1.00x
Memset 234 234 +0.0% 1.00x
Dictionary2OfObjects 3597 3581 -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 3647 3642 -0.1% 1.00x(?)
ObjectiveCBridgeFromNSDictionaryAnyObject 147824 149320 +1.0% 0.99x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 156875 158585 +1.1% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToString 85726 86696 +1.1% 0.99x(?)
StrComplexWalk 2964 2990 +0.9% 0.99x(?)
ObserverUnappliedMethod 2547 2561 +0.6% 0.99x(?)
DictionaryLiteral 1464 1472 +0.6% 0.99x(?)
SortStringsUnicode 7187 7242 +0.8% 0.99x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 95141 96384 +1.3% 0.99x(?)
ObjectiveCBridgeStubDataAppend 3494 3516 +0.6% 0.99x(?)
DictionaryRemove 2320 2338 +0.8% 0.99x(?)
158 2850468 2871778 +0.8% 0.99x
ObserverForwarderStruct 908 917 +1.0% 0.99x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 79066 79619 +0.7% 0.99x(?)
StackPromo 21496 21846 +1.6% 0.98x
DictionaryBridge 3073 3139 +2.1% 0.98x(?)
ReversedDictionary 95 97 +2.1% 0.98x(?)
ErrorHandling 3063 3121 +1.9% 0.98x(?)
Dictionary 749 762 +1.7% 0.98x
ObjectiveCBridgeFromNSSetAnyObjectToString 98833 100925 +2.1% 0.98x(?)
ObjectiveCBridgeFromNSString 1378 1411 +2.4% 0.98x
Array2D 1891 1941 +2.6% 0.97x(?)
ObjectiveCBridgeToNSSet 37141 38225 +2.9% 0.97x(?)
NSDictionaryCastToSwift 5265 5416 +2.9% 0.97x(?)
**Unoptimized (Onone)**
Regression (0)
Improvement (1)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
TypeFlood 218 164 -24.8% 1.33x
No Changes (158)
TEST OLD_MIN NEW_MIN DELTA (%) SPEEDUP
RangeAssignment 7342 7143 -2.7% 1.03x
ErrorHandling 4054 3955 -2.4% 1.03x(?)
ObjectiveCBridgeFromNSArrayAnyObjectForced 9705 9557 -1.5% 1.02x(?)
SuperChars 269574 264441 -1.9% 1.02x(?)
ArrayPlusEqualFiveElementCollection 551531 542566 -1.6% 1.02x(?)
ObjectiveCBridgeStubToNSDate 14989 14671 -2.1% 1.02x(?)
ObjectiveCBridgeFromNSSetAnyObject 74450 73147 -1.8% 1.02x(?)
ObjectiveCBridgeStubNSDateMutationRef 15513 15147 -2.4% 1.02x(?)
DeadArray 122871 120647 -1.8% 1.02x(?)
ObjectiveCBridgeStubNSDataAppend 2644 2601 -1.6% 1.02x(?)
ArrayValueProp 3067 3002 -2.1% 1.02x(?)
ArraySubscript 5667 5624 -0.8% 1.01x
ObjectiveCBridgeFromNSArrayAnyObjectToString 88615 87719 -1.0% 1.01x(?)
DictionaryBridge 3229 3199 -0.9% 1.01x(?)
ObjectiveCBridgeFromNSDictionaryAnyObject 153629 152774 -0.6% 1.01x(?)
StringInterpolation 15554 15394 -1.0% 1.01x(?)
ArrayPlusEqualSingleElementCollection 541310 536302 -0.9% 1.01x(?)
ObjectiveCBridgeStubFromNSString 937 924 -1.4% 1.01x(?)
StaticArray 3771 3728 -1.1% 1.01x
Walsh 13217 13139 -0.6% 1.01x(?)
ObjectiveCBridgeStubURLAppendPathRef 250180 248519 -0.7% 1.01x(?)
StringEqualPointerComparison 9511 9437 -0.8% 1.01x
AngryPhonebook 3398 3368 -0.9% 1.01x(?)
NSDictionaryCastToSwift 6623 6553 -1.1% 1.01x(?)
HashTest 5630 5578 -0.9% 1.01x(?)
ReversedArray 521 518 -0.6% 1.01x(?)
ObjectiveCBridgeFromNSSetAnyObjectForced 6937 6876 -0.9% 1.01x(?)
BitCount 97 96 -1.0% 1.01x
ObjectiveCBridgeToNSString 1302 1303 +0.1% 1.00x(?)
MonteCarloPi 53454 53455 +0.0% 1.00x(?)
RecursiveOwnedParameter 10912 10911 -0.0% 1.00x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectToString 166949 167400 +0.3% 1.00x(?)
ClassArrayGetter 1274 1274 +0.0% 1.00x
Array2D 814253 813696 -0.1% 1.00x(?)
SortStrings 2492 2502 +0.4% 1.00x(?)
ObjectiveCBridgeFromNSDictionaryAnyObjectForced 7850 7854 +0.1% 1.00x(?)
ObjectiveCBridgeStubFromNSDateRef 3999 3994 -0.1% 1.00x(?)
DictionarySwapOfObjects 20590 20493 -0.5% 1.00x(?)
StringWithCString 151625 150916 -0.5% 1.00x
ObjectiveCBridgeFromNSStringForced 2659 2648 -0.4% 1.00x
Prims 12777 12820 +0.3% 1.00x(?)
SortLettersInPlace 2661 2659 -0.1% 1.00x(?)
DictionarySwap 6232 6252 +0.3% 1.00x(?)
ArrayAppendToFromGeneric 713 713 +0.0% 1.00x
ByteSwap 9 9 +0.0% 1.00x
XorLoop 19935 19934 -0.0% 1.00x(?)
ArrayAppendReserved 3048 3049 +0.0% 1.00x
ObserverClosure 7223 7256 +0.5% 1.00x(?)
CharacterLiteralsSmall 972 971 -0.1% 1.00x
ObjectiveCBridgeStubToNSString 1543 1543 +0.0% 1.00x
ArrayAppendStrings 11815 11837 +0.2% 1.00x(?)
ProtocolDispatch 6091 6089 -0.0% 1.00x(?)
ObjectAllocation 611 610 -0.2% 1.00x(?)
SortSortedStrings 1250 1252 +0.2% 1.00x
ArrayLiteral 1443 1437 -0.4% 1.00x
ProtocolDispatch2 439 439 +0.0% 1.00x
CharacterLiteralsLarge 13477 13469 -0.1% 1.00x(?)
Dictionary2 3681 3675 -0.2% 1.00x(?)
Join 1464 1467 +0.2% 1.00x(?)
ObserverUnappliedMethod 9035 9061 +0.3% 1.00x(?)
ObjectiveCBridgeToNSSet 38349 38409 +0.2% 1.00x(?)
ArrayPlusEqualArrayOfInt 714 711 -0.4% 1.00x
DictionaryOfObjects 4725 4739 +0.3% 1.00x(?)
PopFrontArrayGeneric 9282 9313 +0.3% 1.00x
PopFrontUnsafePointer 177897 177910 +0.0% 1.00x(?)
PolymorphicCalls 687 687 +0.0% 1.00x
RC4 9334 9333 -0.0% 1.00x(?)
ObjectiveCBridgeStubToNSStringRef 147 147 +0.0% 1.00x
Calculator 949 945 -0.4% 1.00x
ArrayAppendFromGeneric 715 713 -0.3% 1.00x(?)
MapReduce 44936 44917 -0.0% 1.00x(?)
ObjectiveCBridgeStubDateMutation 433 433 +0.0% 1.00x
IterateData 10730 10748 +0.2% 1.00x
UTF8Decode 45719 45869 +0.3% 1.00x
ObjectiveCBridgeFromNSDictionaryAnyObjectToStringForced 98355 98582 +0.2% 1.00x(?)
NopDeinit 44500 44443 -0.1% 1.00x(?)
ObjectiveCBridgeStubToArrayOfNSString 31776 31753 -0.1% 1.00x(?)
ObjectiveCBridgeFromNSArrayAnyObject 69154 69315 +0.2% 1.00x(?)
ArrayAppendOptionals 1357 1352 -0.4% 1.00x(?)
ArrayInClass 3956 3957 +0.0% 1.00x(?)
ArrayOfGenericRef 10205 10246 +0.4% 1.00x(?)
ObjectiveCBridgeStubDateAccess 972 971 -0.1% 1.00x
Sim2DArray 14522 14523 +0.0% 1.00x(?)
SetExclusiveOr_OfObjects 39225 39349 +0.3% 1.00x
SetUnion_OfObjects 28236 28298 +0.2% 1.00x
ReversedBidirectional 136130 136334 +0.1% 1.00x(?)
StringHasSuffixUnicode 62079 62323 +0.4% 1.00x
ArrayAppendToGeneric 715 715 +0.0% 1.00x
ArrayAppend 3340 3338 -0.1% 1.00x(?)
DictionaryRemove 17949 17867 -0.5% 1.00x
158 6764477 6792322 +0.4% 1.00x
RGBHistogramOfObjects 84018 84271 +0.3% 1.00x(?)
RGBHistogram 35077 35228 +0.4% 1.00x(?)
ArrayAppendArrayOfInt 711 710 -0.1% 1.00x(?)
ArrayOfPOD 1832 1832 +0.0% 1.00x
Chars 6439 6435 -0.1% 1.00x(?)
ObjectiveCBridgeStubNSDateRefAccess 1188 1186 -0.2% 1.00x(?)
StrToInt 5348 5325 -0.4% 1.00x
AnyHashableWithAClass 79817 79881 +0.1% 1.00x(?)
SevenBoom 1587 1592 +0.3% 1.00x(?)
ObjectiveCBridgeFromNSArrayAnyObjectToStringForced 80632 80844 +0.3% 1.00x(?)
StringWalk 23044 22930 -0.5% 1.00x(?)
ObjectiveCBridgeFromNSString 4025 4036 +0.3% 1.00x(?)
GlobalClass 0 0 +0.0% 1.00x
Memset 20585 20584 -0.0% 1.00x(?)
Dictionary2OfObjects 6013 6017 +0.1% 1.00x(?)
ArrayValueProp4 3375 3376 +0.0% 1.00x(?)
ArrayValueProp2 3539 3531 -0.2% 1.00x(?)
ArrayValueProp3 3438 3426 -0.3% 1.00x(?)
ObjectiveCBridgeStubFromNSDate 3917 3917 +0.0% 1.00x
ObserverPartiallyAppliedMethod 8743 8781 +0.4% 1.00x(?)
PopFrontArray 13402 13518 +0.9% 0.99x
Integrate 364 367 +0.8% 0.99x
Histogram 10286 10343 +0.6% 0.99x(?)
ReversedDictionary 32550 32882 +1.0% 0.99x
Dictionary3OfObjects 2171 2196 +1.1% 0.99x
ArrayAppendLazyMap 275691 278523 +1.0% 0.99x
Dictionary3 1392 1407 +1.1% 0.99x(?)
ArrayOfRef 9236 9354 +1.3% 0.99x
ObjectiveCBridgeToNSArray 31547 31776 +0.7% 0.99x(?)
NSError 687 696 +1.3% 0.99x(?)
ObjectiveCBridgeStubToNSDateRef 3305 3324 +0.6% 0.99x(?)
DictionaryLiteral 16404 16631 +1.4% 0.99x(?)
Hanoi 19212 19369 +0.8% 0.99x
DictionaryRemoveOfObjects 49595 49940 +0.7% 0.99x(?)
SortStringsUnicode 8293 8380 +1.1% 0.99x
SetIntersect 12094 12277 +1.5% 0.99x
SetExclusiveOr 21496 21738 +1.1% 0.99x
ObjectiveCBridgeFromNSSetAnyObjectToString 106597 107585 +0.9% 0.99x(?)
Phonebook 20661 20865 +1.0% 0.99x
ObjectiveCBridgeToNSDictionary 61718 62336 +1.0% 0.99x(?)
MonteCarloE 107727 108375 +0.6% 0.99x
SetIsSubsetOf_OfObjects 1859 1884 +1.3% 0.99x
StringHasPrefixUnicode 15082 15225 +0.9% 0.99x
LinkedList 27610 27798 +0.7% 0.99x
SetUnion 11978 12085 +0.9% 0.99x(?)
ObserverForwarderStruct 5228 5274 +0.9% 0.99x
ObjectiveCBridgeStubFromArrayOfNSString 60394 60812 +0.7% 0.99x(?)
SetIntersect_OfObjects 11625 11919 +2.5% 0.98x
CaptureProp 121692 123889 +1.8% 0.98x
SetIsSubsetOf 2028 2073 +2.2% 0.98x
Dictionary 1884 1914 +1.6% 0.98x
ObjectiveCBridgeStubDataAppend 3542 3602 +1.7% 0.98x(?)
ArrayAppendRepeatCol 213276 216964 +1.7% 0.98x
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 73320 74757 +2.0% 0.98x(?)
TwoSum 4919 5007 +1.8% 0.98x
StackPromo 128109 132659 +3.5% 0.97x
ObjectiveCBridgeStubFromNSStringRef 203 210 +3.5% 0.97x(?)
StringHasPrefix 1585 1638 +3.3% 0.97x
OpenClose 430 443 +3.0% 0.97x
ArrayOfGenericPOD 3232 3320 +2.7% 0.97x
ObjectiveCBridgeStubURLAppendPath 242918 249286 +2.6% 0.97x(?)
StringHasSuffix 1678 1723 +2.7% 0.97x
StringBuilder 2827 2938 +3.9% 0.96x(?)
ArrayAppendSequence 75958 79175 +4.2% 0.96x
StrComplexWalk 7706 8131 +5.5% 0.95x
ArrayAppendGenericStructs 1347 1412 +4.8% 0.95x
NSStringConversion 1263 1324 +4.8% 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: 16 GB

@gparker42
Copy link
Contributor

I saw similar Linux link errors indicating failure to use atomic instructions in #5282. I didn't investigate and instead added -latomic in a few places. You should steal those diffs if you want to just let Linux suffer for now.

@rjmccall
Copy link
Contributor Author

rjmccall commented Jan 28, 2017

@gparker42 There should be references to the memory from each slab in the cache data structures; that should be sufficient to silence tools, assuming they're silenced today when those data structures are referring to malloc'ed memory. I mean, I guess it's possible that an entire slab could be leaked from high-level contention, but I wouldn't stay up nights worrying about it.

I don't have concrete measurements about pool usage. Those would be good to get.

Yeah, I think adding -latomic is probably the easiest solution. It looks like the implementation is unnecessarily conditionalized (are there any x86_64 processors that don't support that instruction?) but still does use the instruction. If people care about supporting this maximally efficiently there, they can add a target-specific customization, or better yet teach GCC/libstdc++ to just emit the optimal code pattern.

@gparker42
Copy link
Contributor

Okay, the cache references to the slabs ought to be good enough. It would be easy to tweak in response to feedback.

@rjmccall rjmccall force-pushed the global-slab-metadata-allocator branch from e8f0ced to b80aa14 Compare January 28, 2017 02:55
@rjmccall
Copy link
Contributor Author

@swift-ci Please smoke test.

@rjmccall rjmccall force-pushed the global-slab-metadata-allocator branch from b80aa14 to e488413 Compare January 28, 2017 03:18
@rjmccall
Copy link
Contributor Author

@swift-ci Please smoke test Linux.

@rjmccall rjmccall force-pushed the global-slab-metadata-allocator branch from e488413 to 4003b5c Compare January 28, 2017 05:51
@rjmccall
Copy link
Contributor Author

@swift-ci Please smoke test Linux.

@rjmccall rjmccall force-pushed the global-slab-metadata-allocator branch from 4003b5c to 254db8a Compare January 28, 2017 06:28
@rjmccall
Copy link
Contributor Author

@swift-ci Please smoke test Linux.

@rjmccall
Copy link
Contributor Author

Hmm. That seems to be a real, semantic failure.

Okay, seriously, whose bright idea was it to give LLVM allocators these two Deallocate overloads?

  void Deallocate(const void *ptr, size_t allocSize);
  template <class T> void Deallocate(const T *ptr, size_t count = 1);

This is just beyond stupid.

This seems to more than fix a performance regression that we
detected on a metadata-allocation microbenchmark.

A few months ago, I improved the metadata cache representation
and changed the metadata allocation scheme to primarily use malloc.
Previously, we'd been using malloc in the concurrent tree data
structure but a per-cache slab allocator for the metadata itself.
At the time, I was concerned about the overhead of per-cache
allocators, since many metadata patterns see only a small number
of instantiations.  That's still an important factor, so in the
new scheme we're using a global allocator; but instead of using
malloc for individual allocations, we're using a slab allocator,
which should have better peak, single-thread performance, at the
cost of not easily supporting deallocation.  Deallocation is
only used for metadata when there's contention on the cache, and
specifically only when there's contention for the same key, so
leaking a little isn't the worst thing in the world.

The initial slab is a 64K globally-allocated buffer.
Successive slabs are 16K and allocated with malloc.

rdar://28189496
@rjmccall rjmccall force-pushed the global-slab-metadata-allocator branch from 254db8a to ccbe5fc Compare January 28, 2017 07:37
@atrick
Copy link
Contributor

atrick commented Jan 28, 2017

From the commit log:

However, this highlights problematic overloading between the void* and
the T* deallocation functions. I'm looking into a better way to do this,
but as it happens, it comes up rarely in the codebase.

Whose bright idea was it to allow this in a language?

@rjmccall
Copy link
Contributor Author

Heh.

Alright, let's try this again.

@swift-ci Please smoke test Linux.

@rjmccall
Copy link
Contributor Author

@swift-ci Please smoke test OS X and merge.

@rjmccall
Copy link
Contributor Author

@swift-ci Please smoke test OS X.

@rjmccall
Copy link
Contributor Author

Please?

@rjmccall rjmccall merged commit 7df2fa1 into swiftlang:master Jan 28, 2017
@rjmccall rjmccall deleted the global-slab-metadata-allocator branch January 28, 2017 22:17
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