-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Refactor Mirror to reduce metadata allocation #32041
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
Refactor Mirror to reduce metadata allocation #32041
Conversation
Refactor Mirror.descendents Add EitherSequence Create custom reflected children type Switch Mirror to use EitherSequence
@swift-ci please benchmark |
@swift-ci please test |
Performance: -O
Code size: -OPerformance: -Osize
Code size: -OsizePerformance: -Onone
Code size: -swiftlibsHow to read the dataThe 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 Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
Build failed |
@swift-ci smoke test linux |
extension _Either { | ||
init<T, C: Collection>( | ||
_ collection: C | ||
) where Right == AnyCollection<T>, C.Element == T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can drop T
by expressing this as Right == AnyCollection<C.Element>
- Refactor Mirror.descendents - Add _Either sequence - Create custom reflected children type - Switch Mirror to use _Either Co-authored-by: Ben Cohen <[email protected]>
Mirror uses
AnyCollection
to type erase thechildren
between different custom mirror implementations and it's own default implementation. It was previously creating anAnyCollection
to store the children on creation, and this was quite costly both in object and metadata creation.This switches to an internal
Either
type to store the default children implementation, and only resorts toAnyCollection
for custom implementations. This avoids the box allocation if you don't access the children. UnfortunatelyMirror.children: AnyCollection<Any>
is ABI, but internally the standard library can take a faster path.