Skip to content

SILOptimizer: support for Dictionary literals generated in the data section. #24205

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 1 commit into from
Apr 23, 2019

Conversation

eeckstein
Copy link
Contributor

Actually: generate the array of (key, value) tuples in the data section, which is then passed to Dictionary.init(dictionaryLiteral:)
We already do this for simple arrays, e.g. arrays with trivial element types.
The only change needed for dictionary literals is to support tuple types in the ObjectOutliner.

The effect of this optimization is a significant reduction in code size for dictionary literals - and an increase in data size.
But in most cases there is a considerable net win for code+data size in total.

@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci benchmark

@swift-ci
Copy link
Contributor

Code size: -O

TEST OLD NEW DELTA RATIO
Improvement
Prims.o 39736 16952 -57.3% 2.34x
PrimsSplit.o 39806 17022 -57.2% 2.34x
StrToInt.o 5092 3508 -31.1% 1.45x
DictionaryBridgeToObjC.o 6166 5286 -14.3% 1.17x
DictionaryLiteral.o 1363 1251 -8.2% 1.09x
StringMatch.o 4430 4078 -7.9% 1.09x
RomanNumbers.o 8507 8027 -5.6% 1.06x
ErrorHandling.o 3097 2953 -4.6% 1.05x
DictionaryOfAnyHashableStrings.o 10724 10340 -3.6% 1.04x
Combos.o 7408 7232 -2.4% 1.02x
RangeReplaceableCollectionPlusDefault.o 6205 6077 -2.1% 1.02x
UTF8Decode.o 13322 13066 -1.9% 1.02x
StringBuilder.o 7784 7656 -1.6% 1.02x
ObjectiveCBridging.o 50748 50044 -1.4% 1.01x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Improvement
DictionaryLiteral 5910 4640 -21.5% 1.27x

Code size: -Osize

TEST OLD NEW DELTA RATIO
Improvement
Prims.o 37312 14128 -62.1% 2.64x
PrimsSplit.o 37382 14198 -62.0% 2.63x
DictionaryBridgeToObjC.o 5403 4619 -14.5% 1.17x
StringMatch.o 4385 4033 -8.0% 1.09x
DictionaryLiteral.o 1075 995 -7.4% 1.08x
RomanNumbers.o 8722 8242 -5.5% 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: 8-Core Intel Xeon E5
  Processor Speed: 3 GHz
  Number of Processors: 1
  Total Number of Cores: 8
  L2 Cache (per Core): 256 KB
  L3 Cache: 25 MB
  Memory: 64 GB

@gottesmm
Copy link
Contributor

Nice!

unsigned TupleIdx = TEA->getFieldNo();
assert(TupleIdx < NumTailTupleElements);
for (Operand *Use : TEA->getUses()) {
if (!handleTailAddr(TailIdx * NumTailTupleElements + TupleIdx, Use->getUser(), 0,TailStores))
Copy link
Contributor

Choose a reason for hiding this comment

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

This line looks too long :)

llvm::DenseMap<VarDecl *, StoreInst *> MemberStores;

// A store for each element of the tail allocated array. In case of a tuple, there is a store
// for each tuple element. For example, a 3 element0 array of 2-element tuples
Copy link
Contributor

Choose a reason for hiding this comment

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

typo "element0"

…ection.

Actually: generate the array of (key, value) tuples in the data section, which is then passed to Dictionary.init(dictionaryLiteral:)
We already do this for simple arrays, e.g. arrays with trivial element types.
The only change needed for dictionary literals is to support tuple types in the ObjectOutliner.

The effect of this optimization is a significant reduction in code size for dictionary literals - and an increase in data size.
But in most cases there is a considerable net win for code+data size in total.
@eeckstein eeckstein force-pushed the outline-dictionary-literals branch from b918497 to a402544 Compare April 23, 2019 16:03
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test and merge

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test and merge

@swift-ci swift-ci merged commit 42092c5 into swiftlang:master Apr 23, 2019
@eeckstein eeckstein deleted the outline-dictionary-literals branch April 23, 2019 17:35
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