swift
swift copied to clipboard
Conditionally enable bounds checking for unsafe buffer pointers
Currently, bounds checking is only enabled for unsafe buffer pointers in debug builds. Introduce a new precondition check kind, _boundsCheckPrecondition, and use it for the bounds checking of unsafe buffer pointers. This check is enabled both in debug builds and in builds where the experimental feature UnsafePointerBoundsSafety is enabled.
Also add [unchecked:] and [uncheckedBounds:] subscripts to Collection and the various array and buffer types, which only perform bounds checking in debug builds. These can be used in places where the optimizer is not eliminating bounds checks that it should be.
@swift-ci please smoke test
@swift-ci please benchmark
@swift-ci please smoke test
@swift-ci please benchmark
@swift-ci please smoke test
Performance (x86_64): -O
| Regression | OLD | NEW | DELTA | RATIO |
|---|---|---|---|---|
| FlattenListFlatMap | 2853.0 | 4297.0 | +50.6% | 0.66x (?) |
| AngryPhonebook | 275.414 | 359.116 | +30.4% | 0.77x (?) |
| AngryPhonebook.ASCII2.Small | 113.833 | 148.0 | +30.0% | 0.77x (?) |
| ArrayAppendGenericStructs | 1387.5 | 1790.0 | +29.0% | 0.78x (?) |
| LessSubstringSubstring | 24.259 | 30.594 | +26.1% | 0.79x (?) |
| EqualSubstringString | 24.364 | 30.692 | +26.0% | 0.79x (?) |
| EqualSubstringSubstring | 24.613 | 30.92 | +25.6% | 0.80x (?) |
| UTF8Decode_InitFromData | 142.667 | 177.7 | +24.6% | 0.80x (?) |
| EqualStringSubstring | 24.815 | 30.8 | +24.1% | 0.81x (?) |
| EqualSubstringSubstringGenericEquatable | 24.704 | 30.594 | +23.8% | 0.81x (?) |
| UTF8Decode_InitFromBytes | 147.25 | 178.4 | +21.2% | 0.83x |
| String.replaceSubrange.String.Small | 38.87 | 45.821 | +17.9% | 0.85x (?) |
| AngryPhonebook.Strasse | 538.75 | 627.333 | +16.4% | 0.86x (?) |
| StringWordBuilderReservingCapacity | 1140.714 | 1326.154 | +16.3% | 0.86x (?) |
| DistinctClassFieldAccesses | 40.378 | 46.923 | +16.2% | 0.86x (?) |
| StringWordBuilder | 1177.143 | 1363.636 | +15.8% | 0.86x (?) |
| SubstringEqualString | 175.889 | 203.0 | +15.4% | 0.87x (?) |
| StringComparison_longSharedPrefix | 210.2 | 241.222 | +14.8% | 0.87x (?) |
| PrefixWhileAnySequence | 195.0 | 222.889 | +14.3% | 0.87x (?) |
| PrefixWhileSequence | 195.1 | 222.0 | +13.8% | 0.88x (?) |
| String.replaceSubrange.String | 9.478 | 10.783 | +13.8% | 0.88x (?) |
| AngryPhonebook.Cyrillic | 596.5 | 678.0 | +13.7% | 0.88x (?) |
| String.initRepeating.1AsciiChar.Count100 | 476.5 | 541.333 | +13.6% | 0.88x (?) |
| AngryPhonebook.Armenian | 569.75 | 645.667 | +13.3% | 0.88x |
| StringHasSuffixAscii | 3462.0 | 3916.0 | +13.1% | 0.88x (?) |
| FlattenListLoop | 1448.0 | 1624.0 | +12.2% | 0.89x (?) |
| Breadcrumbs.UTF16ToIdx.longASCII | 39.313 | 43.582 | +10.9% | 0.90x (?) |
| StringBuilder | 233.333 | 256.0 | +9.7% | 0.91x (?) |
| String.replaceSubrange.ArrChar.Small | 39.333 | 42.739 | +8.7% | 0.92x (?) |
| StringEnumRawValueInitialization | 394.815 | 424.762 | +7.6% | 0.93x (?) |
| Improvement | OLD | NEW | DELTA | RATIO |
| KeyPathNestedStructs | 6.853 | 3.324 | -51.5% | 2.06x |
| KeyPathsSmallStruct | 21.438 | 10.537 | -50.8% | 2.03x |
| KeyPathReadPerformance | 29.568 | 18.711 | -36.7% | 1.58x |
| Dictionary4 | 239.333 | 157.4 | -34.2% | 1.52x |
| Dictionary4OfObjects | 263.833 | 189.429 | -28.2% | 1.39x |
| Array.removeAll.keepingCapacity.Object | 7.376 | 5.75 | -22.0% | 1.28x (?) |
| UTF8Decode_InitDecoding | 167.9 | 139.286 | -17.0% | 1.21x (?) |
| UTF8Decode_InitFromCustom_contiguous | 167.154 | 139.385 | -16.6% | 1.20x (?) |
| Data.hash.Medium | 28.074 | 24.29 | -13.5% | 1.16x (?) |
| UTF8Decode_InitFromCustom_noncontiguous | 208.0 | 182.3 | -12.4% | 1.14x (?) |
| NormalizedIterator_emoji | 365.231 | 323.034 | -11.6% | 1.13x (?) |
| NormalizedIterator_nonBMPSlowestPrenormal | 474.5 | 430.233 | -9.3% | 1.10x (?) |
| ArrayAppendAscii | 2043.4 | 1888.889 | -7.6% | 1.08x (?) |
| NormalizedIterator_slowerPrenormal | 317.073 | 295.366 | -6.8% | 1.07x (?) |
Code size: -O
Performance (x86_64): -Osize
| Regression | OLD | NEW | DELTA | RATIO |
|---|---|---|---|---|
| Array.removeAll.keepingCapacity.Object | 5.577 | 7.461 | +33.8% | 0.75x (?) |
| AngryPhonebook | 273.237 | 360.267 | +31.9% | 0.76x (?) |
| AngryPhonebook.ASCII2.Small | 113.706 | 147.786 | +30.0% | 0.77x (?) |
| EqualSubstringSubstring | 23.844 | 30.279 | +27.0% | 0.79x (?) |
| EqualStringSubstring | 23.833 | 30.259 | +27.0% | 0.79x (?) |
| EqualSubstringSubstringGenericEquatable | 23.941 | 30.269 | +26.4% | 0.79x (?) |
| LessSubstringSubstringGenericComparable | 24.946 | 31.345 | +25.7% | 0.80x (?) |
| EqualSubstringString | 24.813 | 31.135 | +25.5% | 0.80x (?) |
| LessSubstringSubstring | 24.917 | 31.258 | +25.4% | 0.80x (?) |
| UTF8Decode_InitFromData | 142.091 | 177.727 | +25.1% | 0.80x (?) |
| UTF8Decode_InitFromBytes | 144.0 | 178.222 | +23.8% | 0.81x (?) |
| StringWordBuilderReservingCapacity | 1145.0 | 1355.385 | +18.4% | 0.84x (?) |
| SubstringEqualString | 177.364 | 209.333 | +18.0% | 0.85x (?) |
| String.replaceSubrange.String.Small | 39.103 | 46.0 | +17.6% | 0.85x (?) |
| StringComparison_longSharedPrefix | 205.667 | 239.3 | +16.4% | 0.86x (?) |
| StringWordBuilder | 1191.667 | 1385.0 | +16.2% | 0.86x (?) |
| AngryPhonebook.Strasse | 539.5 | 627.0 | +16.2% | 0.86x (?) |
| String.replaceSubrange.String | 9.588 | 10.986 | +14.6% | 0.87x (?) |
| Breadcrumbs.UTF16ToIdx.longASCII | 39.322 | 44.673 | +13.6% | 0.88x (?) |
| AngryPhonebook.Cyrillic | 597.333 | 678.0 | +13.5% | 0.88x (?) |
| String.initRepeating.1AsciiChar.Count100 | 477.25 | 541.25 | +13.4% | 0.88x (?) |
| AngryPhonebook.Armenian | 570.25 | 645.667 | +13.2% | 0.88x (?) |
| NormalizedIterator_fastPrenormal | 488.958 | 539.535 | +10.3% | 0.91x (?) |
| ArrayInClass | 200.694 | 219.571 | +9.4% | 0.91x (?) |
| StringBuilder | 235.25 | 257.0 | +9.2% | 0.92x (?) |
| SubstringFromLongString2 | 23.943 | 26.129 | +9.1% | 0.92x (?) |
| StringBuilderSmallReservingCapacity | 242.857 | 263.5 | +8.5% | 0.92x (?) |
| Breadcrumbs.MutatedUTF16ToIdx.ASCII | 2.476 | 2.666 | +7.7% | 0.93x (?) |
| Improvement | OLD | NEW | DELTA | RATIO |
| KeyPathsSmallStruct | 21.479 | 10.589 | -50.7% | 2.03x |
| KeyPathNestedStructs | 7.469 | 3.735 | -50.0% | 2.00x |
| KeyPathReadPerformance | 29.571 | 18.738 | -36.6% | 1.58x |
| UTF8Decode_InitFromCustom_contiguous | 169.0 | 140.083 | -17.1% | 1.21x |
| UTF8Decode_InitDecoding | 168.4 | 141.909 | -15.7% | 1.19x (?) |
| Data.hash.Medium | 28.074 | 24.265 | -13.6% | 1.16x (?) |
| UTF8Decode_InitFromCustom_noncontiguous | 331.0 | 304.143 | -8.1% | 1.09x (?) |
Code size: -Osize
Performance (x86_64): -Onone
| Regression | OLD | NEW | DELTA | RATIO |
|---|---|---|---|---|
| ArrayAppendReserved | 2547.143 | 3226.0 | +26.7% | 0.79x (?) |
| EqualStringSubstring | 28.542 | 35.8 | +25.4% | 0.80x (?) |
| ObjectiveCBridgeStubDateMutation | 348.6 | 435.75 | +25.0% | 0.80x (?) |
| EqualSubstringSubstring | 28.72 | 35.828 | +24.7% | 0.80x (?) |
| LessSubstringSubstringGenericComparable | 26.577 | 33.097 | +24.5% | 0.80x (?) |
| EqualSubstringSubstringGenericEquatable | 27.656 | 34.4 | +24.4% | 0.80x (?) |
| UTF8Decode_InitFromData | 143.833 | 178.6 | +24.2% | 0.81x |
| UTF8Decode_InitFromBytes | 146.75 | 181.1 | +23.4% | 0.81x |
| EqualSubstringString | 29.063 | 35.815 | +23.2% | 0.81x (?) |
| LessSubstringSubstring | 28.656 | 35.207 | +22.9% | 0.81x (?) |
| StringWordBuilder | 1386.667 | 1647.273 | +18.8% | 0.84x |
| StringWordBuilderReservingCapacity | 1350.833 | 1592.5 | +17.9% | 0.85x |
| BinaryFloatingPointPropertiesBinade | 53.174 | 61.857 | +16.3% | 0.86x (?) |
| AngryPhonebook.Strasse | 540.0 | 627.333 | +16.2% | 0.86x (?) |
| String.replaceSubrange.String.Small | 41.148 | 47.32 | +15.0% | 0.87x (?) |
| ObjectiveCBridgeStubDateAccess | 3258.0 | 3726.0 | +14.4% | 0.87x (?) |
| PrefixCountableRange | 261.714 | 297.714 | +13.8% | 0.88x (?) |
| SuffixCountableRange | 90.941 | 103.0 | +13.3% | 0.88x (?) |
| AngryPhonebook.Cyrillic | 599.25 | 678.333 | +13.2% | 0.88x (?) |
| AngryPhonebook.Armenian | 570.5 | 645.667 | +13.2% | 0.88x (?) |
| DropLastCountableRange | 90.895 | 102.75 | +13.0% | 0.88x (?) |
| DropFirstCountableRange | 261.714 | 295.571 | +12.9% | 0.89x (?) |
| ArraySetElement | 809.5 | 911.0 | +12.5% | 0.89x |
| XorLoop | 4489.0 | 5018.0 | +11.8% | 0.89x (?) |
| BinaryFloatingPointPropertiesUlp | 70.778 | 79.0 | +11.6% | 0.90x (?) |
| DataSubscriptMedium | 56.625 | 63.158 | +11.5% | 0.90x (?) |
| Data.hash.Empty | 99.133 | 109.643 | +10.6% | 0.90x (?) |
| ObjectiveCBridgeStubNSDateRefAccess | 3369.0 | 3723.0 | +10.5% | 0.90x (?) |
| String.replaceSubrange.String | 11.659 | 12.851 | +10.2% | 0.91x (?) |
| BinaryFloatingPointPropertiesNextUp | 67.458 | 74.3 | +10.1% | 0.91x (?) |
| DataSubscriptSmall | 76.118 | 82.75 | +8.7% | 0.92x (?) |
| ObjectiveCBridgeStubToNSStringRef | 111.5 | 120.923 | +8.5% | 0.92x (?) |
| Improvement | OLD | NEW | DELTA | RATIO |
| KeyPathsSmallStruct | 21.939 | 10.1 | -54.0% | 2.17x |
| SubstringRemoveFirst1 | 0.222 | 0.143 | -35.4% | 1.55x (?) |
| KeyPathNestedStructs | 16.769 | 13.185 | -21.4% | 1.27x (?) |
| ArrayAppendGenericStructs | 1390.0 | 1130.0 | -18.7% | 1.23x (?) |
| UTF8Decode_InitDecoding | 175.333 | 148.0 | -15.6% | 1.18x (?) |
| UTF8Decode_InitFromCustom_contiguous | 177.7 | 150.417 | -15.4% | 1.18x (?) |
| KeyPathReadPerformance | 47.167 | 40.462 | -14.2% | 1.17x (?) |
| NSStringConversion.InlineBuffer.ASCII | 5884.0 | 5193.0 | -11.7% | 1.13x (?) |
| NSStringConversion.InlineBuffer.UTF8 | 3574.0 | 3202.0 | -10.4% | 1.12x (?) |
| Data.hash.Medium | 32.44 | 29.091 | -10.3% | 1.12x (?) |
Code size: -swiftlibs
How to read the data
The tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the regressions before you merge the PR.
Noise: Sometimes the performance results (not code size!) contain false alarms. Unexpected regressions which are marked with '(?)' are probably noise. If you see regressions which you cannot explain you can try to run the benchmarks again. If regressions still show up, please consult with the performance team (@eeckstein).
Hardware Overview
Model Name: Mac mini
Model Identifier: Macmini8,1
Processor Name: 6-Core Intel Core i7
Processor Speed: 3.2 GHz
Number of Processors: 1
Total Number of Cores: 6
L2 Cache (per Core): 256 KB
L3 Cache: 12 MB
Memory: 32 GB
Nice!
Collection has three _failEarlyRangeCheck requirements and default implementations.
-
Should the default implementations be changed, to match the documentation comments?
-
UnsafeRawBufferPointer doesn't implement any of the methods, but it has a TODO comment.
-
UnsafeBufferPointer doesn't implement the method with a ClosedRange parameter, and neither do many other types.
@benrimmington (EDITED) the default implementations use _precondition, which is the right thing: we're already unconditionally doing bounds checking, so there's nothing to update.
What do you think about providing specific implementations of these for UnsafeRawBufferPointer, @glessard?
As for the ClosedRange version... I don't know why we're missing them, but I'd like to separate out that task from this bounds-safety one.
@swift-ci please test
@swift-ci please benchmark
Now updated with comprehensive checking, as well as the subscript(unchecked:) and subscript(uncheckedBounds:) operations.
From the last benchmark run...
Performance (x86_64): -O
| Regression | OLD | NEW | DELTA | RATIO |
|---|---|---|---|---|
| AngryPhonebook | 278.091 | 433.054 | +55.7% | 0.64x |
| AngryPhonebook.ASCII2.Small | 113.938 | 175.417 | +54.0% | 0.65x |
| SubstringEqualString | 165.273 | 222.667 | +34.7% | 0.74x |
| SequenceAlgosAnySequence | 19570.0 | 24822.222 | +26.8% | 0.79x (?) |
| DropLastAnySeqCntRangeLazy | 31955.0 | 40516.0 | +26.8% | 0.79x |
| DropLastAnySeqCRangeIterLazy | 32507.0 | 41074.0 | +26.4% | 0.79x |
| SuffixAnySeqCntRangeLazy | 31915.0 | 40029.0 | +25.4% | 0.80x |
| SuffixAnySeqCRangeIterLazy | 32191.0 | 40117.0 | +24.6% | 0.80x |
| UTF8Decode_InitDecoding | 139.727 | 172.818 | +23.7% | 0.81x |
| UTF8Decode_InitFromCustom_contiguous | 140.154 | 173.077 | +23.5% | 0.81x (?) |
| UTF8Decode_InitFromCustom_noncontiguous | 180.143 | 212.0 | +17.7% | 0.85x |
| String.replaceSubrange.String.Small | 40.741 | 47.533 | +16.7% | 0.86x (?) |
| SubstringEquatable | 328.833 | 382.8 | +16.4% | 0.86x |
| Data.hash.Medium | 24.3 | 28.094 | +15.6% | 0.86x (?) |
| NormalizedIterator_fastPrenormal | 464.231 | 534.419 | +15.1% | 0.87x (?) |
| String.replaceSubrange.Substring | 11.0 | 12.643 | +14.9% | 0.87x (?) |
| SuffixAnyCollectionLazy | 15769.0 | 17894.0 | +13.5% | 0.88x |
| NormalizedIterator_latin1 | 168.545 | 190.783 | +13.2% | 0.88x (?) |
| StringWordBuilderReservingCapacity | 1205.714 | 1364.615 | +13.2% | 0.88x (?) |
| String.initRepeating.1AsciiChar.Count100 | 483.0 | 543.5 | +12.5% | 0.89x (?) |
| StringHasPrefixAscii | 3703.333 | 4166.0 | +12.5% | 0.89x (?) |
| StringDistance.utf16.mixed | 71.333 | 80.0 | +12.1% | 0.89x (?) |
| CStringLongNonAscii | 139.429 | 156.333 | +12.1% | 0.89x (?) |
| PrefixAnyCollectionLazy | 47199.0 | 52908.0 | +12.1% | 0.89x |
| StringHasSuffixUnicode | 72176.471 | 80388.889 | +11.4% | 0.90x (?) |
| StringWordBuilder | 1264.286 | 1406.667 | +11.3% | 0.90x (?) |
| DropLastAnyCollectionLazy | 15884.0 | 17642.0 | +11.1% | 0.90x (?) |
| DropFirstAnyCollectionLazy | 47420.0 | 52582.0 | +10.9% | 0.90x (?) |
| Breadcrumbs.IdxToUTF16Range.longMixed | 273.0 | 302.0 | +10.6% | 0.90x (?) |
| StringHasSuffixAscii | 3800.0 | 4200.0 | +10.5% | 0.90x (?) |
| AngryPhonebook.Strasse | 561.75 | 620.667 | +10.5% | 0.91x (?) |
| AngryPhonebook.Cyrillic | 607.75 | 669.0 | +10.1% | 0.91x (?) |
| NormalizedIterator_ascii | 93.154 | 102.286 | +9.8% | 0.91x (?) |
| CxxStringConversion.cxx.to.swift | 113.5 | 124.5 | +9.7% | 0.91x (?) |
| AngryPhonebook.Armenian | 583.5 | 638.0 | +9.3% | 0.91x (?) |
| NormalizedIterator_emoji | 311.484 | 340.296 | +9.2% | 0.92x (?) |
| Breadcrumbs.MutatedIdxToUTF16.ASCII | 2.5 | 2.728 | +9.1% | 0.92x (?) |
| String.replaceSubrange.Substring.Small | 44.885 | 48.952 | +9.1% | 0.92x (?) |
| Breadcrumbs.IdxToUTF16.longMixed | 734.5 | 795.0 | +8.2% | 0.92x (?) |
| KeyPathWritePerformance | 27.0 | 29.081 | +7.7% | 0.93x (?) |
| DropLastSequenceLazy | 296.286 | 318.833 | +7.6% | 0.93x (?) |
| Improvement | OLD | NEW | DELTA | RATIO |
| KeyPathNestedStructs | 6.844 | 3.286 | -52.0% | 2.08x |
| KeyPathsSmallStruct | 21.477 | 10.543 | -50.9% | 2.04x |
| KeyPathReadPerformance | 29.568 | 18.759 | -36.6% | 1.58x (?) |
| Dictionary4 | 191.833 | 156.4 | -18.5% | 1.23x |
| Dictionary4OfObjects | 219.333 | 183.429 | -16.4% | 1.20x |
| FlattenListLoop | 1624.0 | 1387.0 | -14.6% | 1.17x (?) |
| Breadcrumbs.UTF16ToIdx.longASCII | 45.759 | 39.328 | -14.1% | 1.16x (?) |
| StringBuilderSmallReservingCapacity | 265.714 | 239.125 | -10.0% | 1.11x (?) |
Code size: -O
Performance (x86_64): -Osize
| Regression | OLD | NEW | DELTA | RATIO |
|---|---|---|---|---|
| AngryPhonebook | 273.125 | 432.297 | +58.3% | 0.63x |
| AngryPhonebook.ASCII2.Small | 113.625 | 174.917 | +53.9% | 0.65x |
| SubstringEqualString | 168.846 | 213.889 | +26.7% | 0.79x (?) |
| SequenceAlgosAnySequence | 19580.0 | 24750.0 | +26.4% | 0.79x (?) |
| SuffixAnySeqCntRangeLazy | 31745.0 | 39952.0 | +25.9% | 0.79x |
| SuffixAnySeqCRangeIterLazy | 31879.0 | 40035.0 | +25.6% | 0.80x |
| DropLastAnySeqCntRangeLazy | 32245.0 | 40122.0 | +24.4% | 0.80x |
| DropLastAnySeqCRangeIterLazy | 32623.0 | 40183.0 | +23.2% | 0.81x |
| UTF8Decode_InitFromCustom_contiguous | 140.615 | 172.091 | +22.4% | 0.82x (?) |
| UTF8Decode_InitDecoding | 139.636 | 170.0 | +21.7% | 0.82x (?) |
| Data.hash.Medium | 24.292 | 28.517 | +17.4% | 0.85x (?) |
| String.replaceSubrange.Substring | 11.111 | 12.882 | +15.9% | 0.86x (?) |
| SubstringEquatable | 335.0 | 385.8 | +15.2% | 0.87x (?) |
| String.replaceSubrange.String.Small | 40.621 | 46.769 | +15.1% | 0.87x (?) |
| StringHasPrefixAscii | 3652.0 | 4162.0 | +14.0% | 0.88x (?) |
| OpenClose | 52.261 | 58.818 | +12.5% | 0.89x (?) |
| CStringLongNonAscii | 139.615 | 156.545 | +12.1% | 0.89x (?) |
| StringDistance.utf16.mixed | 70.5 | 78.933 | +12.0% | 0.89x (?) |
| PrefixAnyCollectionLazy | 47927.0 | 53425.0 | +11.5% | 0.90x (?) |
| StringWordBuilderReservingCapacity | 1216.667 | 1345.0 | +10.5% | 0.90x (?) |
| SuffixAnyCollectionLazy | 15891.0 | 17550.0 | +10.4% | 0.91x (?) |
| StringHasSuffixUnicode | 72200.0 | 79736.842 | +10.4% | 0.91x (?) |
| AngryPhonebook.Strasse | 560.75 | 619.25 | +10.4% | 0.91x (?) |
| NormalizedIterator_ascii | 91.923 | 101.5 | +10.4% | 0.91x (?) |
| StringHasSuffixAscii | 3812.0 | 4204.0 | +10.3% | 0.91x (?) |
| RemoveWhereFilterString | 220.8 | 243.4 | +10.2% | 0.91x (?) |
| NSStringConversion.Rebridge | 50.8 | 55.974 | +10.2% | 0.91x (?) |
| Breadcrumbs.IdxToUTF16Range.longMixed | 273.667 | 301.333 | +10.1% | 0.91x (?) |
| String.initRepeating.1AsciiChar.Count100 | 493.25 | 540.5 | +9.6% | 0.91x (?) |
| StringWordBuilder | 1259.286 | 1379.231 | +9.5% | 0.91x (?) |
| StringFromLongWholeSubstring | 2.827 | 3.075 | +8.8% | 0.92x (?) |
| StringDistance.utf16.ascii | 138.882 | 151.0 | +8.7% | 0.92x (?) |
| RomanNumbers2 | 455.25 | 492.75 | +8.2% | 0.92x (?) |
| Chars2 | 3227.273 | 3493.103 | +8.2% | 0.92x (?) |
| ArrayAppendAscii | 1876.375 | 2028.667 | +8.1% | 0.92x (?) |
| Breadcrumbs.MutatedIdxToUTF16.ASCII | 2.534 | 2.737 | +8.0% | 0.93x (?) |
| DropLastAnyCollectionLazy | 16502.0 | 17763.0 | +7.6% | 0.93x (?) |
| Improvement | OLD | NEW | DELTA | RATIO |
| KeyPathsSmallStruct | 21.511 | 10.571 | -50.9% | 2.03x |
| KeyPathNestedStructs | 7.471 | 3.806 | -49.0% | 1.96x |
| KeyPathReadPerformance | 29.629 | 18.762 | -36.7% | 1.58x |
| FlattenListFlatMap | 3800.0 | 2620.0 | -31.1% | 1.45x (?) |
| FlattenListLoop | 1386.0 | 986.0 | -28.9% | 1.41x (?) |
| Breadcrumbs.UTF16ToIdx.longASCII | 43.586 | 39.313 | -9.8% | 1.11x |
| StringAdder | 309.333 | 280.0 | -9.5% | 1.10x (?) |
| CharacterRecognizer.ascii | 102.722 | 93.647 | -8.8% | 1.10x (?) |
| String.replaceSubrange.String | 10.782 | 9.833 | -8.8% | 1.10x (?) |
| UTF8Decode_InitFromData_ascii_as_ascii | 181.0 | 166.273 | -8.1% | 1.09x (?) |
| Data.hash.Empty | 56.63 | 52.25 | -7.7% | 1.08x (?) |
| StringInterpolationManySmallSegments | 6652.381 | 6214.286 | -6.6% | 1.07x (?) |
Code size: -Osize
Performance (x86_64): -Onone
| Regression | OLD | NEW | DELTA | RATIO |
|---|---|---|---|---|
| StringWithCString2 | 0.006 | 0.01 | +57.1% | 0.64x |
| PrefixWhileCountableRange | 22762.0 | 29687.0 | +30.4% | 0.77x |
| PrefixWhileAnyCollection | 46939.0 | 59927.0 | +27.7% | 0.78x |
| DropFirstAnySeqCRangeIter | 32560.0 | 41425.0 | +27.2% | 0.79x |
| SuffixAnyCollection | 8090.0 | 10275.0 | +27.0% | 0.79x |
| PrefixAnyCollection | 23978.0 | 30259.0 | +26.2% | 0.79x |
| DropLastAnyCollection | 7975.0 | 10064.0 | +26.2% | 0.79x |
| SequenceAlgosAnySequence | 19922.222 | 25075.0 | +25.9% | 0.79x (?) |
| DropWhileAnyCollection | 31794.0 | 39928.0 | +25.6% | 0.80x |
| DropFirstAnyCollection | 24083.0 | 30244.0 | +25.6% | 0.80x |
| DropFirstAnySeqCntRange | 32697.0 | 41051.0 | +25.5% | 0.80x |
| DropFirstAnySeqCntRangeLazy | 32776.0 | 41012.0 | +25.1% | 0.80x |
| DropWhileCountableRange | 7931.0 | 9919.0 | +25.1% | 0.80x |
| ObjectiveCBridgeStubDateMutation | 348.6 | 435.75 | +25.0% | 0.80x |
| SequenceAlgosRange | 1955680.0 | 2436690.0 | +24.6% | 0.80x |
| DropWhileAnySeqCRangeIter | 37170.0 | 46162.0 | +24.2% | 0.81x |
| LazilyFilteredRange | 849290.0 | 1050740.0 | +23.7% | 0.81x |
| PrefixAnySeqCRangeIter | 26370.0 | 32601.0 | +23.6% | 0.81x |
| SuffixAnySeqCntRangeLazy | 34838.0 | 43043.0 | +23.6% | 0.81x (?) |
| DropWhileAnySeqCntRange | 37157.0 | 45860.0 | +23.4% | 0.81x |
| PrefixAnySeqCntRangeLazy | 25931.0 | 31999.0 | +23.4% | 0.81x |
| SuffixAnySeqCntRange | 34162.0 | 42141.0 | +23.4% | 0.81x |
| PrefixAnySeqCntRange | 26529.0 | 32689.0 | +23.2% | 0.81x |
| SuffixAnySeqCRangeIterLazy | 34983.0 | 43062.0 | +23.1% | 0.81x |
| PrefixAnySeqCRangeIterLazy | 25926.0 | 31905.0 | +23.1% | 0.81x |
| DropFirstAnySeqCRangeIterLazy | 33295.0 | 40957.0 | +23.0% | 0.81x |
| SuffixAnySeqCRangeIter | 34860.0 | 42826.0 | +22.9% | 0.81x |
| DropLastAnySeqCntRange | 35998.0 | 44211.0 | +22.8% | 0.81x |
| DropWhileCountableRangeLazy | 35941.0 | 44097.0 | +22.7% | 0.82x |
| DropWhileAnyCollectionLazy | 36321.0 | 44544.0 | +22.6% | 0.82x |
| PrefixWhileCountableRangeLazy | 27643.0 | 33896.0 | +22.6% | 0.82x |
| DropWhileAnySeqCRangeIterLazy | 36296.0 | 44420.0 | +22.4% | 0.82x |
| DropWhileAnySeqCntRangeLazy | 36202.0 | 44265.0 | +22.3% | 0.82x |
| DropLastAnySeqCRangeIterLazy | 36758.0 | 44861.0 | +22.0% | 0.82x |
| UTF8Decode_InitDecoding | 146.0 | 178.0 | +21.9% | 0.82x (?) |
| DropLastAnySeqCRangeIter | 36566.0 | 44534.0 | +21.8% | 0.82x |
| PrefixWhileAnySeqCntRangeLazy | 28045.0 | 34101.0 | +21.6% | 0.82x |
| DropLastAnySeqCntRangeLazy | 36829.0 | 44775.0 | +21.6% | 0.82x |
| PrefixWhileAnyCollectionLazy | 28343.0 | 34454.0 | +21.6% | 0.82x |
| PrefixWhileAnySeqCRangeIterLazy | 28241.0 | 34297.0 | +21.4% | 0.82x |
| UTF8Decode_InitFromCustom_contiguous | 148.583 | 180.333 | +21.4% | 0.82x (?) |
| DictionaryGroup | 4783.0 | 5740.0 | +20.0% | 0.83x (?) |
| BinaryFloatingPointPropertiesUlp | 66.545 | 78.944 | +18.6% | 0.84x (?) |
| PrefixWhileAnySeqCntRange | 32611.0 | 38449.0 | +17.9% | 0.85x |
| DropLastCountableRangeLazy | 14793.0 | 17378.0 | +17.5% | 0.85x |
| ReversedBidirectional | 55925.0 | 65571.0 | +17.2% | 0.85x |
| PrefixWhileAnySeqCRangeIter | 33532.0 | 39046.0 | +16.4% | 0.86x |
| String.replaceSubrange.String.Small | 42.364 | 49.125 | +16.0% | 0.86x (?) |
| String.replaceSubrange.Substring | 12.528 | 14.5 | +15.7% | 0.86x (?) |
| BinaryFloatingPointPropertiesBinade | 53.136 | 61.478 | +15.7% | 0.86x (?) |
| DropFirstCountableRangeLazy | 44953.0 | 51751.0 | +15.1% | 0.87x |
| PrefixCountableRangeLazy | 45160.0 | 51926.0 | +15.0% | 0.87x |
| RemoveWhereQuadraticInts | 7508.0 | 8564.0 | +14.1% | 0.88x (?) |
| SuffixCountableRangeLazy | 15152.0 | 17264.0 | +13.9% | 0.88x |
| StringWordBuilderReservingCapacity | 1342.308 | 1528.333 | +13.9% | 0.88x (?) |
| Sim2DArray | 5518.0 | 6280.0 | +13.8% | 0.88x (?) |
| CharacterPropertiesPrecomputed | 1786.154 | 2023.636 | +13.3% | 0.88x (?) |
| StringHasPrefixAscii | 5295.0 | 5993.333 | +13.2% | 0.88x |
| StringWordBuilder | 1406.667 | 1590.909 | +13.1% | 0.88x (?) |
| DropLastCountableRange | 90.941 | 102.75 | +13.0% | 0.89x (?) |
| SuffixCountableRange | 90.737 | 102.125 | +12.6% | 0.89x (?) |
| DropFirstCountableRange | 262.143 | 294.857 | +12.5% | 0.89x (?) |
| PrefixCountableRange | 261.875 | 294.429 | +12.4% | 0.89x (?) |
| RemoveWhereFilterString | 318.714 | 357.0 | +12.0% | 0.89x (?) |
| RemoveWhereQuadraticStrings | 8221.0 | 9207.0 | +12.0% | 0.89x (?) |
| SIMDReduce.Int8 | 6422.0 | 7180.0 | +11.8% | 0.89x (?) |
| StringHasSuffixAscii | 5352.5 | 5976.667 | +11.7% | 0.90x (?) |
| DataSubscriptMedium | 56.619 | 63.158 | +11.5% | 0.90x (?) |
| StringInterpolationManySmallSegments | 7453.333 | 8309.091 | +11.5% | 0.90x (?) |
| BinaryFloatingPointPropertiesNextUp | 67.476 | 75.05 | +11.2% | 0.90x (?) |
| DropFirstAnyCollectionLazy | 85641.0 | 94964.0 | +10.9% | 0.90x (?) |
| StringHasSuffixUnicode | 74400.0 | 82473.684 | +10.9% | 0.90x (?) |
| DataCreateEmpty | 807.895 | 893.0 | +10.5% | 0.90x (?) |
| AngryPhonebook.Strasse | 561.75 | 620.0 | +10.4% | 0.91x (?) |
| CharacterPropertiesStashedMemo | 2064.286 | 2277.143 | +10.3% | 0.91x (?) |
| String.initRepeating.1AsciiChar.Count100 | 492.5 | 542.667 | +10.2% | 0.91x (?) |
| CStringLongNonAscii | 156.615 | 172.545 | +10.2% | 0.91x (?) |
| AngryPhonebook.Cyrillic | 607.0 | 668.333 | +10.1% | 0.91x (?) |
| DataCreateMedium | 126600.0 | 139000.0 | +9.8% | 0.91x (?) |
| SuffixSequence | 10841.0 | 11886.0 | +9.6% | 0.91x (?) |
| DropLastAnyCollectionLazy | 28813.0 | 31565.0 | +9.6% | 0.91x (?) |
| AngryPhonebook.Armenian | 581.5 | 637.0 | +9.5% | 0.91x (?) |
| PrefixAnyCollectionLazy | 86548.0 | 94567.0 | +9.3% | 0.92x (?) |
| SuffixAnyCollectionLazy | 28785.0 | 31443.0 | +9.2% | 0.92x (?) |
| SuffixSequenceLazy | 10886.0 | 11841.0 | +8.8% | 0.92x (?) |
| String.replaceSubrange.Substring.Small | 46.32 | 50.269 | +8.5% | 0.92x (?) |
| DataSubscriptSmall | 76.4 | 82.75 | +8.3% | 0.92x (?) |
| Data.hash.Empty | 100.2 | 108.182 | +8.0% | 0.93x (?) |
| Improvement | OLD | NEW | DELTA | RATIO |
| KeyPathsSmallStruct | 21.909 | 10.09 | -53.9% | 2.17x |
| KeyPathNestedStructs | 16.897 | 13.192 | -21.9% | 1.28x |
| KeyPathReadPerformance | 46.684 | 40.786 | -12.6% | 1.14x (?) |
| CharIndexing_punctuated_unicodeScalars_Backwards | 66280.0 | 59920.0 | -9.6% | 1.11x (?) |
| StringEnumRawValueInitialization | 7232.0 | 6743.333 | -6.8% | 1.07x (?) |
| Set.isSuperset.Seq.Int.Empty | 1289.0 | 1202.0 | -6.7% | 1.07x (?) |
Code size: -swiftlibs
How to read the data
The tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the regressions before you merge the PR.
Noise: Sometimes the performance results (not code size!) contain false alarms. Unexpected regressions which are marked with '(?)' are probably noise. If you see regressions which you cannot explain you can try to run the benchmarks again. If regressions still show up, please consult with the performance team (@eeckstein).
Hardware Overview
Model Name: Mac mini
Model Identifier: Macmini8,1
Processor Name: 6-Core Intel Core i7
Processor Speed: 3.2 GHz
Number of Processors: 1
Total Number of Cores: 6
L2 Cache (per Core): 256 KB
L3 Cache: 12 MB
Memory: 32 GB
@swift-ci please smoke test
Interestingly, benchmarks like AngryPhonebook don't use any unsafe stuff. It would be good to look at least into one of those benchmark regressions and try to understand the underlying issue
Maybe the regression stem from the internals for the String implementation, where it would be okay to opt out of bounds checking (because it's stdlib internal and behind the "safety border")
Yes, that's correct.
What do you think about providing specific implementations of these for UnsafeRawBufferPointer?
I think the reason we hadn't done so thus far is that we got away with it. If we no longer get away with it, then we'll add them.
@swift-ci please smoke test
@swift-ci please test
@swift-ci please test