Skip to content

[Runtime] Have ConcurrentReadableHashMap store indices inline when the table is sufficiently small. #34463

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

mikeash
Copy link
Contributor

@mikeash mikeash commented Oct 27, 2020

We use the lower two bits of the indices value to indicate the index size and inline-ness. When stored inline, we can pack 7 or 15 (on 32-bit and 64-bit respectively) values inline, meaning we don't need a heap allocation until we exceed that size, and avoiding the cost of an additional read in those cases.

@mikeash mikeash requested review from xedin, rjmccall and tbkka October 27, 2020 15:55
@mikeash
Copy link
Contributor Author

mikeash commented Oct 27, 2020

@swift-ci please benchmark

@mikeash
Copy link
Contributor Author

mikeash commented Oct 27, 2020

@swift-ci please test

@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
FlattenListLoop 1639 2503 +52.7% 0.65x (?)
FlattenListFlatMap 4774 6556 +37.3% 0.73x (?)
ObjectiveCBridgeFromNSArrayAnyObjectForced 6600 7200 +9.1% 0.92x (?)
SuffixAnyCollection 11 12 +9.1% 0.92x (?)
InsertCharacterEndIndex 165 178 +7.9% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
NSStringConversion.MutableCopy.Rebridge 998 852 -14.6% 1.17x (?)
EqualSubstringString 64 59 -7.8% 1.08x (?)
EqualStringSubstring 66 61 -7.6% 1.08x (?)

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
StringFromLongWholeSubstring 4 5 +25.0% 0.80x
 
Improvement OLD NEW DELTA RATIO
FlattenListFlatMap 6801 5815 -14.5% 1.17x (?)
EqualStringSubstring 66 61 -7.6% 1.08x (?)

Code size: -Osize

Performance: -Onone

Regression OLD NEW DELTA RATIO
SevenBoom 1818 2189 +20.4% 0.83x (?)
EqualSubstringSubstringGenericEquatable 144 159 +10.4% 0.91x (?)
LessSubstringSubstringGenericComparable 146 160 +9.6% 0.91x (?)
NSStringConversion.Rebridge.Mutable 1823 1991 +9.2% 0.92x (?)
StringBuilder 4540 4940 +8.8% 0.92x (?)
DictionaryLiteral 11720 12640 +7.8% 0.93x (?)
ArrayOfPOD 1051 1133 +7.8% 0.93x (?)
StringUTF16Builder 4510 4860 +7.8% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
DictionaryCompactMapValuesOfCastValue 72468 65988 -8.9% 1.10x (?)

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 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

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

Make sense to me!

Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

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

LGTM

@mikeash
Copy link
Contributor Author

mikeash commented Nov 5, 2020

Thanks for checking it over! This doesn't produce the performance win I was hoping for (fewer dependent memory accesses resulting in a minor boost) but as long as it's not a significant slowdown, it's worth it for the memory savings alone. I'm going to re-test and then get it in.

@mikeash
Copy link
Contributor Author

mikeash commented Nov 5, 2020

@swift-ci please test

@mikeash
Copy link
Contributor Author

mikeash commented Nov 6, 2020

@swift-ci please test windows platform

2 similar comments
@mikeash
Copy link
Contributor Author

mikeash commented Nov 9, 2020

@swift-ci please test windows platform

@mikeash
Copy link
Contributor Author

mikeash commented Nov 9, 2020

@swift-ci please test windows platform

@mikeash mikeash merged commit 1b376cd into swiftlang:main Nov 10, 2020
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