awslabs / aws-sdk-swift

Apache License 2.0
370 stars 71 forks source link

Remove Equatable compliance from models & errors #898

Closed jbelkins closed 4 months ago

jbelkins commented 1 year ago

Describe the feature

Currently, smithy-swift code-generates Smithy structs & unions, plus all operation errors, with compliance for Equatable protocol; the Equatable implementation for all of these types is auto-generated by the Swift compiler.

However, the Equatable protocol is almost always not used by the AWS SDK, and results in extra compile time and binary size for no benefit. Informal testing shows that binary size is reduced by 9.6% and compile time is reduced by 16% when Equatable and Hashable conformances are removed from models & errors. (Hashable is being removed separately, in #899.)

Equatable and Hashable conformance should be left on Smithy enums & intEnums, since those types are relatively simple and their primary purpose is to represent one of several alternative states.

There is one place where Equatable is actually used on models, and needs to be addressed to complete this: in rare cases, pagination continuation tokens are Maps which may contain model structs or enums as values; the current pagination scheme requires a pagination token to be Equatable to detect the specific case where a paginated operation endless-loops to return future items as they are created. Currently this arises with two paginators on DynamoDB. There are multiple ways to solve this, some of which may involve keeping generated Equatable compliance on the affected models.

Elimination of Equatable from Smithy structures, unions, and errors will constitute a breaking change because protocol compliance will be removed from public types. This is acceptable because clients should not typically be using AWS models for any purpose outside of making API requests & reading API responses, relying instead on their own models for storing & conveying the data received from an AWS API. (If clients decide they absolutely need Equatable conformance on our models, they are free to manually add them back to AWS models as needed.)

Use Case

This will reduce the compile time and binary size of the AWS SDK with no practical loss of functionality.

Proposed Solution

Remove the Equatable compliance that is added to Smithy structures, unions, and error definitions during code generation, except in the rare cases it is actually needed for SDK function.

Other Information

No response

Acknowledgements

dayaffe commented 10 months ago

Address related TODO: https://github.com/awslabs/aws-sdk-swift/blob/a0ce157d94c295742ff6592c5c81f19408eda9e6/Sources/Core/AWSClientRuntime/EventStream/AWSEventStream.swift#L26

dayaffe commented 4 months ago

Released in 0.43