Skip to content

[ABI] Use faux mangled names for associated conformances in witness tables #20472

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

Conversation

DougGregor
Copy link
Member

The current representation of an associated conformance in a witness
tables (e.g., Iterator: IteratorProtocol within a witness table for
Sequence) is a function that the client calls.

Replace this with something more like what we do for associated types:
an associated conformance is either a pointer to the witness table (once
it is known) or a pointer to a mangled name that describes that
conformance. On first access, demangle the mangled name and replace the
entry with the resulting witness table. This will give us a more compact
representation of associated conformances, as well as always caching
them.

For now, the mangled name is a sham: it’s a mangled relative reference to
the existing witness table accessors, not a true mangled name. In time,
we’ll extend the support here to handle proper mangled names.

Part of rdar://problem/38038799.

@DougGregor
Copy link
Member Author

@swift-ci please benchmark

@DougGregor
Copy link
Member Author

There's one known issue in the test suite I have yet to address, but this should be good enough now for basic benchmarking.

@swift-ci
Copy link
Contributor

swift-ci commented Nov 9, 2018

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Improvement
RandomDoubleLCG 1057 910 -13.9% 1.16x

Code size: -O

TEST OLD NEW DELTA RATIO
Regression
DeadArray.o 1802 1892 +5.0% 0.95x
RangeIteration.o 1626 1700 +4.6% 0.96x
StrToInt.o 4938 5140 +4.1% 0.96x
Fibonacci.o 1554 1612 +3.7% 0.96x
SevenBoom.o 1584 1642 +3.7% 0.96x
ByteSwap.o 1594 1652 +3.6% 0.96x
RangeReplaceableCollectionPlusDefault.o 6083 6301 +3.6% 0.97x
Ackermann.o 1794 1852 +3.2% 0.97x
BitCount.o 1818 1876 +3.2% 0.97x
MonteCarloPi.o 1545 1593 +3.1% 0.97x
NSDictionaryCastToSwift.o 1625 1673 +3.0% 0.97x
Memset.o 2026 2084 +2.9% 0.97x
PointerArithmetics.o 1711 1759 +2.8% 0.97x
ProtocolDispatch2.o 1840 1888 +2.6% 0.97x
LinkedList.o 1894 1942 +2.5% 0.98x
XorLoop.o 1921 1969 +2.5% 0.98x
Integrate.o 2462 2520 +2.4% 0.98x
DictTest2.o 15257 15609 +2.3% 0.98x
Calculator.o 2546 2604 +2.3% 0.98x
StringInterpolation.o 7163 7323 +2.2% 0.98x
Join.o 2240 2288 +2.1% 0.98x
ArrayLiteral.o 3085 3143 +1.9% 0.98x
ArraySubscript.o 3954 4028 +1.9% 0.98x
MonteCarloE.o 3266 3324 +1.8% 0.98x
DictionaryOfAnyHashableStrings.o 10877 11069 +1.8% 0.98x
Prefix.o 23737 24153 +1.8% 0.98x
DropWhile.o 22676 23044 +1.6% 0.98x
PrefixWhile.o 23070 23438 +1.6% 0.98x
OpenClose.o 3111 3159 +1.5% 0.98x
ChainedFilterMap.o 3117 3165 +1.5% 0.98x
LuhnAlgoLazy.o 11684 11856 +1.5% 0.99x
LuhnAlgoEager.o 11686 11858 +1.5% 0.99x
NibbleSort.o 16220 16456 +1.5% 0.99x
Exclusivity.o 4459 4523 +1.4% 0.99x
StrComplexWalk.o 3361 3409 +1.4% 0.99x
DropLast.o 24683 25035 +1.4% 0.99x
StackPromo.o 2295 2327 +1.4% 0.99x
HashQuadratic.o 5434 5508 +1.4% 0.99x
RandomValues.o 3808 3856 +1.3% 0.99x
DictionaryBridge.o 3332 3374 +1.3% 0.99x
DropFirst.o 24276 24580 +1.3% 0.99x
RC4.o 4657 4715 +1.2% 0.99x
NopDeinit.o 5151 5215 +1.2% 0.99x
DictionaryCompactMapValues.o 20798 21054 +1.2% 0.99x
RangeAssignment.o 4882 4940 +1.2% 0.99x
ObjectAllocation.o 4219 4267 +1.1% 0.99x
Suffix.o 25417 25705 +1.1% 0.99x
PopFront.o 5155 5213 +1.1% 0.99x
TwoSum.o 5466 5524 +1.1% 0.99x
PopFrontGeneric.o 4686 4734 +1.0% 0.99x
Improvement
StringBuilder.o 7602 7314 -3.8% 1.04x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
MapReduceLazyCollectionShort 41 85 +107.3% 0.48x
RandomDoubleLCG 883 987 +11.8% 0.89x
CharacterLiteralsLarge 100 111 +11.0% 0.90x
DropWhileAnySeqCntRange 187 205 +9.6% 0.91x
FloatingPointPrinting_Float_description_uniform 5273 5769 +9.4% 0.91x
Improvement
DropWhileAnySeqCntRangeLazy 282 246 -12.8% 1.15x
PrefixWhileAnySeqCntRangeLazy 176 159 -9.7% 1.11x
SuffixCountableRangeLazy 12 11 -8.3% 1.09x
PrefixWhileAnySeqCntRange 252 235 -6.7% 1.07x

Code size: -Osize

TEST OLD NEW DELTA RATIO
Regression
StrToInt.o 5063 5284 +4.4% 0.96x
RangeReplaceableCollectionPlusDefault.o 5520 5741 +4.0% 0.96x
LinkedList.o 1905 1969 +3.4% 0.97x
MonteCarloPi.o 1530 1578 +3.1% 0.97x
BitCount.o 1586 1634 +3.0% 0.97x
Fibonacci.o 1594 1642 +3.0% 0.97x
ByteSwap.o 1634 1682 +2.9% 0.97x
NSDictionaryCastToSwift.o 1658 1706 +2.9% 0.97x
RangeIteration.o 1722 1770 +2.8% 0.97x
SevenBoom.o 1768 1816 +2.7% 0.97x
StringInterpolation.o 6484 6660 +2.7% 0.97x
DictTest4Legacy.o 23337 23961 +2.7% 0.97x
PointerArithmetics.o 1816 1864 +2.6% 0.97x
DeadArray.o 1842 1890 +2.6% 0.97x
Join.o 2501 2565 +2.6% 0.98x
ProtocolDispatch2.o 1884 1932 +2.5% 0.98x
XorLoop.o 1890 1938 +2.5% 0.98x
Ackermann.o 1909 1957 +2.5% 0.98x
Memset.o 1940 1988 +2.5% 0.98x
StackPromo.o 2325 2373 +2.1% 0.98x
Integrate.o 2454 2502 +2.0% 0.98x
Calculator.o 2522 2570 +1.9% 0.98x
ArrayLiteral.o 2936 2984 +1.6% 0.98x
ObjectAllocation.o 4062 4126 +1.6% 0.98x
DictTest3.o 21782 22118 +1.5% 0.98x
ChainedFilterMap.o 3156 3204 +1.5% 0.99x
Exclusivity.o 4324 4388 +1.5% 0.99x
StrComplexWalk.o 3282 3330 +1.5% 0.99x
LuhnAlgoLazy.o 14572 14776 +1.4% 0.99x
LuhnAlgoEager.o 14574 14778 +1.4% 0.99x
DictionaryBridge.o 3452 3500 +1.4% 0.99x
RandomValues.o 3481 3529 +1.4% 0.99x
OpenClose.o 3504 3552 +1.4% 0.99x
MonteCarloE.o 3642 3690 +1.3% 0.99x
RC4.o 3785 3833 +1.3% 0.99x
ArraySubscript.o 3866 3914 +1.2% 0.99x
DictionaryCompactMapValues.o 19326 19550 +1.2% 0.99x

Performance: -Onone

TEST OLD NEW DELTA RATIO
Regression
EqualSubstringString 24 27 +12.5% 0.89x
ByteSwap 9683 10877 +12.3% 0.89x
EqualStringSubstring 18 20 +11.1% 0.90x
IterateData 4989 5523 +10.7% 0.90x
ArraySubscript 110122 120187 +9.1% 0.92x
MonteCarloPi 5450940 5935755 +8.9% 0.92x
MonteCarloE 1178353 1282274 +8.8% 0.92x
BitCount 9103 9882 +8.6% 0.92x
Improvement
PrefixArrayLazy 32313 24961 -22.8% 1.29x
DropLastArrayLazy 10775 8331 -22.7% 1.29x
DropFirstArrayLazy 32257 24999 -22.5% 1.29x
SuffixArrayLazy 10712 8309 -22.4% 1.29x
SuffixCountableRangeLazy 12721 10004 -21.4% 1.27x
DropFirstCountableRangeLazy 38249 30080 -21.4% 1.27x
PrefixCountableRangeLazy 38150 30010 -21.3% 1.27x
DropLastCountableRangeLazy 12717 10025 -21.2% 1.27x
ArrayOfPOD 853 779 -8.7% 1.09x (?)
DropFirstAnyCollectionLazy 115673 106072 -8.3% 1.09x

Code size: -swiftlibs

TEST OLD NEW DELTA RATIO
Regression
libswiftCore.dylib 3227648 3284992 +1.8% 0.98x
libswiftStdlibUnittest.dylib 372736 376832 +1.1% 0.99x
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
--------------

@DougGregor
Copy link
Member Author

The code size regressions are expected (we've strictly added code, via the indirection through the faux mangled name). We expect that real manglings of conformances will provide code size improvements.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test macOS

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test macOS

@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

@DougGregor
Copy link
Member Author

@swift-ci please clean test Linux

2 similar comments
@DougGregor
Copy link
Member Author

@swift-ci please clean test Linux

@DougGregor
Copy link
Member Author

@swift-ci please clean test Linux

@swift-ci
Copy link
Contributor

swift-ci commented Nov 9, 2018

Build failed
Swift Test Linux Platform
Git Sha - a7b459b3181af0dfd0eb8a8167fd3d4b8188ca71

@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

…ables

The current representation of an associated conformance in a witness
tables (e.g., Iterator: IteratorProtocol within a witness table for
Sequence) is a function that the client calls.

Replace this with something more like what we do for associated types:
an associated conformance is either a pointer to the witness table (once
it is known) or a pointer to a mangled name that describes that 
conformance. On first access, demangle the mangled name and replace the
entry with the resulting witness table. This will give us a more compact
representation of associated conformances, as well as always caching
them.

For now, the mangled name is a sham: it’s a mangled relative reference to
the existing witness table accessors, not a true mangled name. In time,
we’ll extend the support here to handle proper mangled names.

Part of rdar://problem/38038799.
If the type checker doesn't prepopulate signature conformances, fill
them in when we first need them. This is a stopgap solution until we
can move these queries over to the request-evaluator.

Fixes rdar://problem/34584596, as well as a regression introduced by
the use of mangled names for associated conformances in witness tables.
…stant.

The runtime can choose to re-use the pattern of a witness table if in fact
there is nothing dependent about it. Only mark the pattern as constant
when we know it has no inline caching behavior.
@DougGregor DougGregor force-pushed the abi-mangled-assoc-conformances-in-witness-tables branch from a7b459b to dbe50c6 Compare November 13, 2018 04:03
@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit 9334458 into swiftlang:master Nov 13, 2018
@DougGregor DougGregor deleted the abi-mangled-assoc-conformances-in-witness-tables branch November 13, 2018 05:14
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