-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Reduce generics in Codable #31278
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
Reduce generics in Codable #31278
Conversation
In particular, types generic on the CodingKey produce a lot of runtime metadata. Reducing the number of such types should help with some of the reported memory bloat from Codable.
@swift-ci Please benchmark |
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
|
This didn't catch any perf regressions on the JSON encode/decode tests. I think we can dismiss the UTF8Decode checks above as unrelated noise, since they're not testing Codable/Decodable. |
@swift-ci Please benchmark |
@@ -3845,237 +3843,237 @@ internal class _KeyedDecodingContainerBase<Key: CodingKey> { | |||
fatalError("_KeyedDecodingContainerBase cannot be used directly.") | |||
} | |||
|
|||
internal var allKeys: [Key] { | |||
internal var allKeys: [CodingKey] { |
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.
@jckarter I don't suppose you have any ideas for improving this one?
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.
Hm. Do we have a way using standard library SPI that we could just store the reference to the array's buffer object here, and construct the Array<Key>
shell around it in the getter?
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.
If the SPI doesn't exist, maybe you could have this variable be of type _ArrayBridgeStorage
and bitcast it back and forth to Array<K>
in the methods that access it.
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
|
… generic and manually asserting that the types match. Based on a suggestion of @jckarter
I implemented @jckarter's suggestion -- let's see if that addresses the perf regression here. |
@swift-ci Please benchmark |
@swift-ci Please benchmark |
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 |
@swift-ci Please test macOS |
@swift-ci Please nominate Explanation: Reduce memory requirements for Codable/Decodable support by making internal types non-generic |
In particular, types generic on the CodingKey produce a lot of runtime metadata. Reducing the number of such types should help with some of the reported memory bloat from Codable. Based on a suggestion of @jckarter Resolves rdar://62620208
In particular, types generic on the CodingKey produce a lot of runtime metadata.
Reducing the number of such types should help with some of the reported memory
bloat from Codable.
Resolves rdar://62620208