Skip to content

[stdlib][DNM] Concretize dropFirst/Last/sufix/prefix from Sequence #19998

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

Closed

Conversation

airspeedswift
Copy link
Member

Further followup to #19995 removing more customization points. This one is different in that it is source breaking – these currently return SubSequence whereas this PR changes them to return specific concrete types.

@airspeedswift
Copy link
Member Author

@swift-ci please benchmark

@airspeedswift
Copy link
Member Author

@swift-ci please test source compatibility

@airspeedswift
Copy link
Member Author

I expect some source compat breakage, question is how much.

@airspeedswift
Copy link
Member Author

Also it would be more efficient to keep forwarding versions of AnySequence.dropFirst() etc, but let's see how much of an issue the benchmarks show up for that first.

@swift-ci

This comment has been minimized.

@airspeedswift
Copy link
Member Author

Ignoring the type-erased benchmarks which we could fix, this is clearly a big performance and code-size win.

@airspeedswift
Copy link
Member Author

The two projects that failed the compat suite are due to a deserialization failure that I believe is unrelated/existing.

@airspeedswift
Copy link
Member Author

@swift-ci please benchmark

@swift-ci

This comment has been minimized.

@airspeedswift
Copy link
Member Author

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

!!! Couldn't read commit file !!!

@airspeedswift
Copy link
Member Author

Jenkins issue?

@airspeedswift
Copy link
Member Author

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Build failed before running benchmark.


@airspeedswift
Copy link
Member Author

@swift-ci please benchmark

@swift-ci

This comment has been minimized.

@airspeedswift
Copy link
Member Author

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
DropLastAnySeqCntRangeLazy 9 20644 +229252.3% 0.00x
SuffixAnySeqCntRangeLazy 14 24201 +172751.9% 0.00x
DropLastAnySeqCntRange 9 519 +5666.0% 0.02x
SuffixAnySeqCntRange 14 760 +5328.2% 0.02x
SuffixAnySeqCRangeIterLazy 3601 24308 +575.0% 0.15x
DropLastAnySeqCRangeIterLazy 3305 20669 +525.4% 0.16x
PrefixAnySeqCRangeIterLazy 31 88 +183.9% 0.35x
PrefixAnySeqCRangeIter 31 88 +183.9% 0.35x
PrefixAnySequence 1374 2214 +61.1% 0.62x
DropFirstAnySeqCRangeIter 58 93 +60.3% 0.62x
DropFirstAnySeqCRangeIterLazy 57 91 +59.6% 0.63x
DropFirstAnySequenceLazy 1855 2724 +46.8% 0.68x
DropWhileAnySequence 1856 2694 +45.2% 0.69x
DropFirstAnySequence 1855 2653 +43.0% 0.70x
DropFirstAnySeqCntRange 71 92 +29.6% 0.77x
DropFirstAnySeqCntRangeLazy 71 91 +28.2% 0.78x
DropWhileAnySeqCRangeIter 75 95 +26.7% 0.79x
PrefixAnySeqCntRange 71 88 +23.9% 0.81x
PrefixAnySeqCntRangeLazy 71 88 +23.9% 0.81x
Improvement
DropWhileSequence 2211 29 -98.7% 76.24x
PrefixSequenceLazy 2264 52 -97.7% 43.54x
PrefixSequence 2214 52 -97.7% 42.58x
DropFirstSequenceLazy 2310 59 -97.4% 39.15x
DropFirstSequence 2260 59 -97.4% 38.30x
SuffixAnySequence 4945 539 -89.1% 9.17x
DropLastAnySequence 4947 547 -88.9% 9.04x
DropLastAnySeqCRangeIter 3305 522 -84.2% 6.33x
SuffixSequence 3654 586 -84.0% 6.24x
SuffixSequenceLazy 3653 586 -84.0% 6.23x
SuffixAnySeqCRangeIter 3610 823 -77.2% 4.39x
DropLastAnySequenceLazy 5025 3413 -32.1% 1.47x
SuffixAnySequenceLazy 5050 3573 -29.2% 1.41x
PrefixWhileAnySeqCRangeIter 388 343 -11.6% 1.13x

Code size: -O

TEST OLD NEW DELTA RATIO
Regression
DropLast.o 25515 26913 +5.5% 0.95x
Suffix.o 26249 27299 +4.0% 0.96x
DropFirst.o 25228 25756 +2.1% 0.98x
Prefix.o 24673 25057 +1.6% 0.98x
Improvement
NibbleSort.o 14348 8482 -40.9% 1.69x
COWTree.o 14564 13676 -6.1% 1.06x
LuhnAlgoLazy.o 18236 17348 -4.9% 1.05x
LuhnAlgoEager.o 18238 17350 -4.9% 1.05x
SequenceAlgos.o 23315 22427 -3.8% 1.04x
DictOfArraysToArrayOfDicts.o 32340 31452 -2.7% 1.03x
Substring.o 27833 27163 -2.4% 1.02x
PrefixWhile.o 24062 23502 -2.3% 1.02x
StringBuilder.o 11679 11455 -1.9% 1.02x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
DropLastAnySeqCRangeIterLazy 3674 20489 +457.7% 0.18x
SuffixAnySeqCRangeIterLazy 3970 20563 +418.0% 0.19x
DropLastAnySeqCntRangeLazy 5265 20409 +287.6% 0.26x
SuffixAnySeqCntRangeLazy 5298 20485 +286.7% 0.26x
DropFirstAnySeqCntRange 17231 23536 +36.6% 0.73x
DropWhileAnyCollectionLazy 252 282 +11.9% 0.89x (?)
SuffixAnyCollection 59 65 +10.2% 0.91x
Improvement
DropWhileAnySeqCRangeIter 17693 163 -99.1% 108.55x
DropFirstAnySeqCRangeIterLazy 21285 213 -99.0% 99.93x
PrefixAnySeqCRangeIterLazy 16865 176 -99.0% 95.82x
PrefixAnySeqCntRangeLazy 15868 167 -98.9% 95.02x
DropWhileSequence 2631 35 -98.7% 75.17x
DropFirstAnySeqCntRangeLazy 15800 213 -98.7% 74.18x
DropFirstSequenceLazy 3038 58 -98.1% 52.38x
DropFirstSequence 2787 58 -97.9% 48.05x
PrefixSequence 2705 70 -97.4% 38.64x
PrefixSequenceLazy 2670 70 -97.4% 38.14x
PrefixWhileAnySeqCRangeIter 9655 346 -96.4% 27.90x
DropLastAnySeqCntRange 5250 532 -89.9% 9.87x
DropLastAnySequence 5565 677 -87.8% 8.22x
SuffixAnySeqCntRange 5334 760 -85.8% 7.02x
DropLastAnySeqCRangeIter 3674 534 -85.5% 6.88x
PrefixWhileAnySequence 11058 1692 -84.7% 6.54x
SuffixAnySequence 5556 944 -83.0% 5.89x
SuffixAnySeqCRangeIter 3970 825 -79.2% 4.81x
SuffixSequenceLazy 3987 956 -76.0% 4.17x
SuffixSequence 3987 956 -76.0% 4.17x
PrefixAnySequenceLazy 4295 1581 -63.2% 2.72x
DropWhileAnySequence 5580 3193 -42.8% 1.75x
DropLastAnySequenceLazy 5637 3698 -34.4% 1.52x
DropFirstAnySequenceLazy 4816 3188 -33.8% 1.51x
SuffixAnySequenceLazy 5606 3894 -30.5% 1.44x
PrefixWhileSequence 488 346 -29.1% 1.41x
DropWhileAnySeqCntRange 205 163 -20.5% 1.26x
PrefixWhileAnyCollectionLazy 176 159 -9.7% 1.11x
DropLastAnyCollection 65 59 -9.2% 1.10x
PrefixAnySequence 4332 3979 -8.1% 1.09x

Code size: -Osize

TEST OLD NEW DELTA RATIO
Regression
StringEdits.o 13814 14200 +2.8% 0.97x
DropFirst.o 23812 24356 +2.3% 0.98x
DropLast.o 25539 26017 +1.9% 0.98x
Prefix.o 23777 24161 +1.6% 0.98x
Suffix.o 25937 26251 +1.2% 0.99x
StringRemoveDupes.o 8973 9077 +1.2% 0.99x
Improvement
NibbleSort.o 19652 12858 -34.6% 1.53x
Substring.o 20129 18681 -7.2% 1.08x
PrefixWhile.o 24446 22782 -6.8% 1.07x
COWTree.o 13682 12794 -6.5% 1.07x
LuhnAlgoLazy.o 15900 15012 -5.6% 1.06x
LuhnAlgoEager.o 15902 15014 -5.6% 1.06x
SequenceAlgos.o 26060 25172 -3.4% 1.04x
CSVParsing.o 37096 35880 -3.3% 1.03x
DictOfArraysToArrayOfDicts.o 32452 31564 -2.7% 1.03x
StringBuilder.o 11210 11066 -1.3% 1.01x

Performance: -Onone

TEST OLD NEW DELTA RATIO
Regression
DropLastAnySeqCntRangeLazy 5545 39231 +607.5% 0.14x
DropLastAnySeqCntRange 5581 38982 +598.5% 0.14x
SuffixAnySeqCntRangeLazy 5543 33085 +496.9% 0.17x
SuffixAnySeqCntRange 5530 32395 +485.8% 0.17x
StringMatch 28975 47665 +64.5% 0.61x (?)
StringUTF16SubstringBuilder 22005 30700 +39.5% 0.72x
StringBuilderWithLongSubstring 3964 5296 +33.6% 0.75x
DropFirstAnySeqCntRangeLazy 16522 22058 +33.5% 0.75x
DropWhileAnySeqCntRange 21535 28741 +33.5% 0.75x
DropFirstAnySeqCntRange 16641 21718 +30.5% 0.77x
StringRemoveDupes 743 943 +26.9% 0.79x
ArrayAppendRepeatCol 202034 239255 +18.4% 0.84x
DataAppendSequence 2077290 2451763 +18.0% 0.85x
LazilyFilteredRange 567095 665939 +17.4% 0.85x
PrefixSequenceLazy 8510 9837 +15.6% 0.87x
PrefixAnySeqCntRangeLazy 16613 18381 +10.6% 0.90x
DropFirstArrayLazy 31695 34282 +8.2% 0.92x
Improvement
PrefixSequence 8575 7378 -14.0% 1.16x
CharIndexing_chinese_unicodeScalars_Backwards 335327 290565 -13.3% 1.15x
DropFirstSequenceLazy 10492 9300 -11.4% 1.13x
DropFirstSequence 10366 9206 -11.2% 1.13x

Code size: Swift libraries

TEST OLD NEW DELTA RATIO
Improvement
libswiftSwiftReflectionTest.dylib 49152 36864 -25.0% 1.33x
libswiftCoreAudio.dylib 32768 24576 -25.0% 1.33x
libswiftsimd.dylib 286720 217088 -24.3% 1.32x
libswiftCloudKit.dylib 98304 81920 -16.7% 1.20x
libswiftDispatch.dylib 114688 98304 -14.3% 1.17x
libswiftCore.dylib 3944448 3596288 -8.8% 1.10x
libswiftFoundation.dylib 1728512 1626112 -5.9% 1.06x
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 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: 64 GB

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.

2 participants