Skip to content

stdlib: two small Array improvements #28486

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 2 commits into from
Dec 2, 2019
Merged

Conversation

eeckstein
Copy link
Contributor

  • make the non-native Array.count smaller more efficient

Use _CocoaArrayWrapper.endIndex which returns the NSArray.count.
In the old version, "count" translated to RandomAccessCollection.count, which ended up in multiple calls to endIndex.

Without this, Array.first compiled down to RandomAccessCollection.first, which ended up in pretty unefficient code.

rdar://problem/46291397

Use _CocoaArrayWrapper.endIndex which returns the NSArray.count.
In the old version, "count" translated to RandomAccessCollection.count, which ended up in multiple calls to endIndex.
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci benchmark

@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
NSStringConversion.Long 492 556 +13.0% 0.88x (?)
StringBuilderLong 840 930 +10.7% 0.90x (?)
Set.isSuperset.Seq.Empty.Int 48 52 +8.3% 0.92x (?)
MapReduceLazyCollectionShort 26 28 +7.7% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
ArrayAppendGenericStructs 910 610 -33.0% 1.49x (?)
EqualSubstringSubstring 27 21 -22.2% 1.29x
LessSubstringSubstring 27 21 -22.2% 1.29x (?)
EqualSubstringSubstringGenericEquatable 27 21 -22.2% 1.29x
LessSubstringSubstringGenericComparable 27 21 -22.2% 1.29x
EqualStringSubstring 28 22 -21.4% 1.27x (?)
Dictionary4 195 157 -19.5% 1.24x
EqualSubstringString 27 22 -18.5% 1.23x
StringComparison_longSharedPrefix 356 319 -10.4% 1.12x (?)
LazilyFilteredArrayContains 18500 16700 -9.7% 1.11x
ArraySetElement 284 263 -7.4% 1.08x (?)
PrefixWhileAnySeqCntRange 203 189 -6.9% 1.07x (?)
ObjectiveCBridgeStubFromNSDate 2810 2620 -6.8% 1.07x (?)

Code size: -O

Improvement OLD NEW DELTA RATIO
ClassArrayGetter.o 5528 5019 -9.2% 1.10x
NopDeinit.o 5297 5044 -4.8% 1.05x
ArrayOfGenericRef.o 11422 10910 -4.5% 1.05x
ArrayOfRef.o 11539 11043 -4.3% 1.04x
COWTree.o 12236 11892 -2.8% 1.03x
DictionaryGroup.o 17573 17224 -2.0% 1.02x

Performance: -Osize

Regression OLD NEW DELTA RATIO
NSStringConversion.Long 484 545 +12.6% 0.89x (?)
NSStringConversion.Medium 234 256 +9.4% 0.91x
 
Improvement OLD NEW DELTA RATIO
LessSubstringSubstring 27 21 -22.2% 1.29x
EqualSubstringString 27 21 -22.2% 1.29x (?)
LessSubstringSubstringGenericComparable 27 21 -22.2% 1.29x
EqualSubstringSubstring 28 22 -21.4% 1.27x (?)
EqualStringSubstring 28 22 -21.4% 1.27x (?)
EqualSubstringSubstringGenericEquatable 28 22 -21.4% 1.27x (?)
Set.subtracting.Empty.Box 8 7 -12.5% 1.14x (?)
RemoveWhereMoveInts 19 17 -10.5% 1.12x (?)
Array2D 4160 3728 -10.4% 1.12x (?)
StringComparison_longSharedPrefix 356 320 -10.1% 1.11x (?)
SortIntPyramid 530 480 -9.4% 1.10x
DataCreateEmptyArray 1650 1500 -9.1% 1.10x (?)
ArraySetElement 284 264 -7.0% 1.08x (?)

Code size: -Osize

Improvement OLD NEW DELTA RATIO
ClassArrayGetter.o 5619 5125 -8.8% 1.10x
NopDeinit.o 6257 5838 -6.7% 1.07x
ArrayOfRef.o 12635 12091 -4.3% 1.04x
ArrayOfGenericRef.o 12598 12070 -4.2% 1.04x
COWTree.o 13020 12508 -3.9% 1.04x
DictionaryGroup.o 13684 13396 -2.1% 1.02x
DictionarySubscriptDefault.o 17559 17335 -1.3% 1.01x
MapReduce.o 25459 25203 -1.0% 1.01x

Performance: -Onone

Improvement OLD NEW DELTA RATIO
LazilyFilteredArrays2 82900 48900 -41.0% 1.70x
BucketSort 8231 6176 -25.0% 1.33x
EqualSubstringSubstring 32 26 -18.7% 1.23x (?)
EqualSubstringSubstringGenericEquatable 31 26 -16.1% 1.19x (?)
LessSubstringSubstringGenericComparable 31 26 -16.1% 1.19x (?)
LessSubstringSubstring 32 27 -15.6% 1.19x (?)
EqualStringSubstring 32 27 -15.6% 1.19x
EqualSubstringString 32 27 -15.6% 1.19x
ArrayOfPOD 722 648 -10.2% 1.11x (?)

Code size: -swiftlibs

Improvement OLD NEW DELTA RATIO
libswiftStdlibUnittest.dylib 360448 356352 -1.1% 1.01x
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: 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: 64 GB

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - ed69ab5456ae082a309c19d4825404f5dfe39663

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - ed69ab5456ae082a309c19d4825404f5dfe39663

This makes Array.first much small and more efficient.
Without this, Array.first compiled down to RandomAccessCollection.first, which ended up in pretty unefficient code.

rdar://problem/46291397
@eeckstein
Copy link
Contributor Author

@swift-ci test

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci test

Copy link
Member

@airspeedswift airspeedswift left a comment

Choose a reason for hiding this comment

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

thanks!

@eeckstein eeckstein merged commit 3170017 into swiftlang:master Dec 2, 2019
@eeckstein eeckstein deleted the array-first branch December 2, 2019 07:50
meg-gupta added a commit to meg-gupta/swift that referenced this pull request May 18, 2020
Similar to swiftlang#28486 in motivation.
Before this change 'count' got lowered to multiple 'endIndex' calls

Fixes rdar://46702232
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.

3 participants