-
Notifications
You must be signed in to change notification settings - Fork 847
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
DynamoDBEntryConversion AOT compatibility #3300
base: main-staging
Are you sure you want to change the base?
Conversation
@@ -41,7 +39,9 @@ public partial class DynamoDBContext : IDynamoDBContext | |||
/// <param name="value">Object to save.</param> | |||
/// <param name="cancellationToken">Token which can be used to cancel the task.</param> | |||
/// <returns>A Task that can be used to poll or wait for results, or both.</returns> | |||
public Task SaveAsync<T>(T value, CancellationToken cancellationToken = default(CancellationToken)) | |||
#pragma warning disable IL2095 // 'DynamicallyAccessedMemberTypes' on the generic parameter of method or type don't match overridden generic parameter method or type. All overridden members must have the same 'DynamicallyAccessedMembersAttribute' usage. | |||
public Task SaveAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(T value, CancellationToken cancellationToken = default(CancellationToken)) |
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.
Added to test AOT changes. I would create a separate PR with such annotations if approved.
@@ -0,0 +1,53 @@ | |||
#if !NET6_0_OR_GREATER |
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.
Just added it here to avoid constant #if NET8_0_OR_GREATER diectives
I was looking into ways to improve AOT compatibility (and performance), and decided to rework a bit DynamoDBEntryConversion. Since it's a substantial piece of work, I decided to create a Draft PR (without tests, maybe something else) for further discussion. |
FYI I have written for NServiceBus DynamoDB persistence a system.text.json based wrapper that also allows to plug in source generated json context. The approach is fairly library like and we would be happy to contribute it back to the AWS SDK if it can be plugged into the dynamodb context. Simple Class Serialization and DeserializationNested Class Serialization and DeserializationAnd these numbers are already quite old and would probably look even better today on NET8 |
@normj Still, if you think that it's too big of a change or goes in unwanted direction - feel free to close this PR, I would be fine with that as well :) |
Related to #2542.
I was looking into improving AOT compatibility for DynamoDB, and decided to submit a POC for further discussion.
With this PR all DynamoDbEntryConverion-related types are AOT compatible.
Description
GetTargetTypes
method anymore, therefore they don't need to construct generic types.Motivation and Context
Testing
As I mentioned, I haven't added any unit tests until it is discussed, since I wasn't sure that this approach would be approved or even considered.
I've added a small Aot project, which I have tested using Local DynamoDb. I failed due triming issues before, but works fine now.
It doesn't support nested object (which is expected without a source generator), but it could be resolved by adding TrimmerRootAssembly to csproj file.
In order to test performance impact, I have created the following benchmark:
Benchmark
Benchmark results
Simple job (main):
Simple job (this branch):
Cold start (main):
Cold start (this branch):
As you can see, there is a significant performance improvement both in speed and memory use, mostly for collection conversions.
Screenshots (if appropriate)
Types of changes
Checklist
License