Skip to content

[stdlib] Remove additional customization points #19995

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

Conversation

airspeedswift
Copy link
Member

@airspeedswift airspeedswift commented Oct 23, 2018

This removes some unnecessary customization points on standard library protocols:

map, filter and forEach on Sequence

It is unrealistic that a collection would be able to implement map (which takes a transformation closure) to create a mapped array faster than the default implementation.

While it is possible that a type's forEach implementation might be able to eek out a small performance benefit (for example, to avoid the reference count bump of putting self into an iterator), it is generally harmful to encourage this kind of "maybe forEach could be faster" micro-optimization (for example, see here where error control flow was used in order to break out of the for-each early).

first on Collection and last on BidirectionalCollection

It's important to remove these in order for collections of move-only types to be able to implement these protocols. Returning a single element of the collection inside an optional would otherwise need to consume the entire collection.

While it is conceivable that faster implementations of first for particular collections could exist, it's unlikely to be material and experience in benchmarking so far suggests that where they did exist, those implementations were actually slower.

Amended as brought up on the review thread to add more entries:

suffix(from:), prefix(upTo:) and prefix(through:)

These are trivial and really don't need to be customizable.

@airspeedswift
Copy link
Member Author

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Improvement
IterateData 1742 1621 -6.9% 1.07x (?)

Code size: -O

TEST OLD NEW DELTA RATIO
Improvement
NibbleSort.o 14536 12448 -14.4% 1.17x
COWTree.o 14900 14660 -1.6% 1.02x
LuhnAlgoLazy.o 18256 18016 -1.3% 1.01x
LuhnAlgoEager.o 18258 18018 -1.3% 1.01x
SequenceAlgos.o 23379 23139 -1.0% 1.01x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Improvement
IterateData 1806 1591 -11.9% 1.14x
RemoveWhereFilterString 340 312 -8.2% 1.09x

Code size: -Osize

TEST OLD NEW DELTA RATIO
Regression
StringRemoveDupes.o 8973 9077 +1.2% 0.99x
Improvement
NibbleSort.o 19752 17000 -13.9% 1.16x
COWTree.o 14078 13838 -1.7% 1.02x
LuhnAlgoLazy.o 15920 15680 -1.5% 1.02x
LuhnAlgoEager.o 15922 15682 -1.5% 1.02x

Performance: -Onone

TEST OLD NEW DELTA RATIO
Improvement
StringInterpolationSmall 6571 6110 -7.0% 1.08x

Code size: Swift libraries

TEST OLD NEW DELTA RATIO
Improvement
libswiftCoreAudio.dylib 32768 28672 -12.5% 1.14x
libswiftsimd.dylib 286720 266240 -7.1% 1.08x
libswiftCloudKit.dylib 102400 98304 -4.0% 1.04x
libswiftCore.dylib 3969024 3858432 -2.8% 1.03x
libswiftFoundation.dylib 1839104 1810432 -1.6% 1.02x
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

@airspeedswift
Copy link
Member Author

@swift-ci please test

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@airspeedswift airspeedswift force-pushed the even-less-customization branch 2 times, most recently from 5046158 to a211184 Compare October 26, 2018 02:56
@airspeedswift
Copy link
Member Author

@swift-ci please test

@swift-ci

This comment has been minimized.

@airspeedswift airspeedswift force-pushed the even-less-customization branch from a211184 to 3228f7e Compare October 29, 2018 14:38
@airspeedswift
Copy link
Member Author

@swift-ci please smoke test

@airspeedswift airspeedswift force-pushed the even-less-customization branch from 3228f7e to 6bc7073 Compare October 30, 2018 21:53
@airspeedswift
Copy link
Member Author

@swift-ci please smoke test

@airspeedswift airspeedswift force-pushed the even-less-customization branch from 6bc7073 to a122cfb Compare October 31, 2018 15:41
@airspeedswift
Copy link
Member Author

@swift-ci please smoke test

@airspeedswift
Copy link
Member Author

@swift-ci please smoke test linux platform

1 similar comment
@airspeedswift
Copy link
Member Author

@swift-ci please smoke test linux platform

@airspeedswift
Copy link
Member Author

@swift-ci please test linux platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - a211184de1473beca456847814d67f886784f5cf

@airspeedswift airspeedswift merged commit dbc2e21 into swiftlang:master Nov 1, 2018
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