Skip to content

[metadata prespecialization] Support for classes. #30089

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

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Feb 27, 2020

When generic metadata for a class is requested in the same module where the class is defined, rather than a call to the generic metadata accessor or to a variant of typeForMangledNode, a call to a new accessor--a canonical specialized generic metadata accessor--is emitted.
The new function is defined schematically as follows:

    MetadataResponse `canonical specialized metadata accessor for C<K>`(MetadataRequest request) {
      (void)`canonical specialized metadata accessor for superclass(C<K>)`(::Complete)
      (void)`canonical specialized metadata accessor for generic_argument_class(C<K>, 1)`(::Complete)
      ...
      (void)`canonical specialized metadata accessor for generic_argument_class(C<K>, count)`(::Complete)
      auto *metadata = objc_opt_self(`canonical specialized metadata for C<K>`);
      return {metadata, MetadataState::Complete};
    }

To enable these new canonical specialized generic metadata accessors, metadata for generic classes is prespecialized as needed. So are the metaclasses and the corresponding rodata.

Previously, the lazy objc naming hook was registered during process execution when the first generic class metadata was instantiated. Since that instantiation may occur "before process launch" (i.e. if the generic metadata is prespecialized), the lazy naming hook is now
installed at process launch.

@nate-chandler
Copy link
Contributor Author

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Build failed before running benchmark.

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/classes branch from e469b54 to ad7b89e Compare February 28, 2020 01:36
@nate-chandler
Copy link
Contributor Author

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
FlattenListFlatMap 7092 7925 +11.7% 0.89x (?)
 
Improvement OLD NEW DELTA RATIO
LazilyFilteredArrayContains 35700 30200 -15.4% 1.18x
ArrayAppendLazyMap 6980 6070 -13.0% 1.15x
ObjectiveCBridgeStringHash 78 68 -12.8% 1.15x
ObjectiveCBridgeStringGetASCIIContents 328 305 -7.0% 1.08x

Code size: -O

Performance: -Osize

Improvement OLD NEW DELTA RATIO
ObjectiveCBridgeStringHash 78 68 -12.8% 1.15x
String.data.LargeUnicode 109 96 -11.9% 1.14x (?)
ArrayAppendLazyMap 7900 6980 -11.6% 1.13x (?)
ObjectiveCBridgeStringGetASCIIContents 327 305 -6.7% 1.07x (?)

Code size: -Osize

Performance: -Onone

Regression OLD NEW DELTA RATIO
UTF8Decode_InitDecoding_ascii 398 431 +8.3% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
ObjectiveCBridgeStubFromNSDate 5930 5020 -15.3% 1.18x (?)
ObjectiveCBridgeStringHash 79 68 -13.9% 1.16x
ArrayOfPOD 1123 1042 -7.2% 1.08x (?)
ObjectiveCBridgeStringGetASCIIContents 328 305 -7.0% 1.08x (?)

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

@airspeedswift
Copy link
Member

Is it surprising we didn't see improvement at -Onone like we did with the struct metadata?

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/classes branch from ad7b89e to 821659b Compare March 4, 2020 21:16
@nate-chandler
Copy link
Contributor Author

@swift-ci please benchmark

@nate-chandler
Copy link
Contributor Author

@airspeedswift This isn't quite done yet, but even when it is, we may need to directly refer to some specializations of generic classes to see similar performance changes.

@swift-ci
Copy link
Contributor

swift-ci commented Mar 4, 2020

Performance: -O

Regression OLD NEW DELTA RATIO
EqualSubstringSubstring 40 44 +10.0% 0.91x (?)
EqualSubstringSubstringGenericEquatable 40 44 +10.0% 0.91x (?)
EqualStringSubstring 41 45 +9.8% 0.91x (?)
EqualSubstringString 41 45 +9.8% 0.91x (?)
 
Improvement OLD NEW DELTA RATIO
ArrayAppendLazyMap 7140 6100 -14.6% 1.17x
ObjectiveCBridgeStringHash 78 67 -14.1% 1.16x
LazilyFilteredArrayContains 34900 30200 -13.5% 1.16x
String.data.LargeUnicode 97 89 -8.2% 1.09x (?)
InsertCharacterEndIndexNonASCII 61 56 -8.2% 1.09x (?)
ObjectiveCBridgeStringGetASCIIContents 329 305 -7.3% 1.08x (?)

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
EqualStringSubstring 40 44 +10.0% 0.91x (?)
UTF8Decode_InitFromBytes_ascii 289 313 +8.3% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
ObjectiveCBridgeStringHash 78 67 -14.1% 1.16x
ArrayAppendLazyMap 7900 6990 -11.5% 1.13x (?)
ObjectiveCBridgeStringGetASCIIContents 328 304 -7.3% 1.08x (?)
StringComparison_emoji 808 752 -6.9% 1.07x (?)

Code size: -Osize

Performance: -Onone

Regression OLD NEW DELTA RATIO
UTF8Decode_InitFromData_ascii_as_ascii 675 738 +9.3% 0.91x (?)
UTF8Decode_InitFromBytes_ascii_as_ascii 493 535 +8.5% 0.92x (?)
LessSubstringSubstring 47 51 +8.5% 0.92x (?)
ArrayOfPOD 1035 1116 +7.8% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
ObjectiveCBridgeStringHash 78 67 -14.1% 1.16x
String.data.Empty 38 35 -7.9% 1.09x (?)
String.data.Small 41 38 -7.3% 1.08x (?)
ObjectiveCBridgeStringGetASCIIContents 330 306 -7.3% 1.08x (?)

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

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/classes branch 4 times, most recently from 232cc58 to 35a6172 Compare March 11, 2020 18:23
@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/classes branch 4 times, most recently from cbd1d12 to d3cfca1 Compare March 13, 2020 16:43
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - ad7b89e311905b6eb9f9888f11222430b1b1e2e3

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - ad7b89e311905b6eb9f9888f11222430b1b1e2e3

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/classes branch 3 times, most recently from bd8d35a to 1f8bdd4 Compare March 14, 2020 00:47
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 1f8bdd46247df2bfcbcc2b40a680a860d8ddf947

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 1f8bdd46247df2bfcbcc2b40a680a860d8ddf947

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/classes branch from 1f8bdd4 to da6a524 Compare March 17, 2020 20:57
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 1f8bdd46247df2bfcbcc2b40a680a860d8ddf947

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/classes branch from 71bb637 to 3cbed7b Compare May 22, 2020 01:45
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/classes branch from 3cbed7b to da20de1 Compare May 27, 2020 21:57
@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 71bb637e2fa144b8a2ba60de611ed61a0e1230b0

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 71bb637e2fa144b8a2ba60de611ed61a0e1230b0

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/classes branch from da20de1 to 668b088 Compare May 27, 2020 22:02
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 3cbed7b1834a59421d26b2d0cb6b618b90230a73

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3cbed7b1834a59421d26b2d0cb6b618b90230a73

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test linux platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 668b088450eed2a44d6b3d4b61d4e65433851e8a

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/classes branch from 668b088 to a8e949c Compare May 28, 2020 21:56
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 668b088450eed2a44d6b3d4b61d4e65433851e8a

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 668b088450eed2a44d6b3d4b61d4e65433851e8a

@nate-chandler
Copy link
Contributor Author

@swift-ci please test macos platform

When generic metadata for a class is requested in the same module where
the class is defined, rather than a call to the generic metadata
accessor or to a variant of typeForMangledNode, a call to a new
accessor--a canonical specialized generic metadata accessor--is emitted.
The new function is defined schematically as follows:

    MetadataResponse `canonical specialized metadata accessor for C<K>`(MetadataRequest request) {
      (void)`canonical specialized metadata accessor for superclass(C<K>)`(::Complete)
      (void)`canonical specialized metadata accessor for generic_argument_class(C<K>, 1)`(::Complete)
      ...
      (void)`canonical specialized metadata accessor for generic_argument_class(C<K>, count)`(::Complete)
      auto *metadata = objc_opt_self(`canonical specialized metadata for C<K>`);
      return {metadata, MetadataState::Complete};
    }

where generic_argument_class(C<K>, N) denotes the Nth generic argument
which is both (1) itself a specialized generic type and is also (2) a
class.  These calls to the specialized metadata accessors for these
related types ensure that all generic class types are registered with
the Objective-C runtime.

To enable these new canonical specialized generic metadata accessors,
metadata for generic classes is prespecialized as needed. So are the
metaclasses and the corresponding rodata.

Previously, the lazy objc naming hook was registered during process
execution when the first generic class metadata was instantiated. Since
that instantiation may occur "before process launch" (i.e. if the
generic metadata is prespecialized), the lazy naming hook is now
installed at process launch.
@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/classes branch from a8e949c to bdef1ce Compare May 29, 2020 20:20
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - a8e949c787042dafc2bdbbd8817d9ebce27f49f2

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - a8e949c787042dafc2bdbbd8817d9ebce27f49f2

@nate-chandler
Copy link
Contributor Author

@swift-ci please test macos platform

@nate-chandler
Copy link
Contributor Author

@swift-ci please test linux platform

@nate-chandler nate-chandler merged commit 5204af3 into swiftlang:master May 30, 2020
@nate-chandler nate-chandler deleted the generic-metadata-prespecialization-components/classes branch May 30, 2020 00:32
@compnerd
Copy link
Member

This breaks the Windows bots because the test case file names are far too long. The file system limits files to 260 characters. Could you please rename the files?

@nate-chandler
Copy link
Contributor Author

@compnerd as mentioned there, let's just fix the filename, rather than reverting and recommitting.

@compnerd
Copy link
Member

@nate-chandler responded there as well, but renaming definitely is better.

@nate-chandler
Copy link
Contributor Author

@compnerd Renaming PR at #32098 .

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