Repository navigation
fix(batch): remove Native AOT warnings from BatchProcessing - #1370
Merged
Merged
Conversation
- DynamoDbRecordDataExtractor serializes a named type with a source-generated context instead of an anonymous type with reflection. - JsonDeserializationService guards reflection-based deserialization with JsonSerializer.IsReflectionEnabledByDefault; remove the unused AotCompatibilityHelper.FallbackDeserialize. - Typed [BatchProcessor] handlers call ProcessAsync<T> through the ITypedBatchProcessor interface from a statically known generic method, and reject value-type record data under Native AOT with a clear error. - Annotate the typed handler provider properties with PublicMethods. Closes #1332
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #1370 +/- ##
===========================================
+ Coverage 80.29% 80.36% +0.06%
===========================================
Files 303 304 +1
Lines 12962 12960 -2
Branches 1551 1547 -4
===========================================
+ Hits 10408 10415 +7
+ Misses 2098 2090 -8
+ Partials 456 455 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Issue number: closes #1332
Summary
Changes
Removes the 12 Powertools-owned trim/AOT warnings that a Native AOT publish of a BatchProcessing app reports. It also fixes typed
[BatchProcessor]handlers, which didn't work under Native AOT at all.DynamoDbRecordDataExtractor.ExtractDataserialized an anonymous type with reflectionDynamoDbRecordDatain a source-generatedBatchProcessingSerializationContext. The JSON is unchanged (a test pins it to the old output).JsonDeserializationService.DeserializeWithFallback<T>[RequiresUnreferencedCode]/[RequiresDynamicCode]helper that is only called insideJsonSerializer.IsReflectionEnabledByDefault && RuntimeFeatureWrapper.IsDynamicCodeSupported, so ILC removes it. A#pragmais kept only for the Roslyn analyzer, which doesn't treat that check as a guard.AotCompatibilityHelper.FallbackDeserialize<T>BatchProcessorAttribute:GetMethod("Create")on the typed provider typesTypedRecordHandlerProviderandTypedRecordHandlerWithContextProviderare now annotated withPublicMethods.GetMethods), IL2060TypedBatchProcessingAspectHandler: searched the processor's runtime type forProcessAsyncProcessAsync<T>calls the processor throughITypedBatchProcessor<,>, and it is resolved with a statically knownGetMethod.MakeGenericMethod(dataType)UniversalWrapperAspect(#1346): under Native AOT only reference types reach it, and those share canonical code. Value-type record data now fails with a clearNotSupportedException.GetInterfaces)Tfrom the handler instance (provider-created handlers have no annotated type)ITypedRecordHandler<T>/ITypedRecordHandlerWithContext<T>.ProcessAsync<T>casts the handler to those interfaces and is always compiled, so ILC keeps them. The runtime check below covers both direct and provider-created handlers.Call flow for typed handlers:
AotCompatibilityHelper.IsAotModenow readsRuntimeFeatureWrapper, so tests can simulate Native AOT. Value-type return types of[BatchProcessor]methods aren't covered here; #1345 handles those.User experience
Before, under Native AOT (3.2.2 package), every typed
[BatchProcessor]handler failed before processing any record:After, typed handlers behave the same under Native AOT as under JIT. Two cases still fail under Native AOT, now with clear messages (both are documented in
docs/utilities/batch-processing.md):JsonSerializerContext:AotCompatibilityException("AOT compilation requires a JsonSerializerContext for type 'Order'...")NotSupportedException("Typed record handler 'ValueTypeHandler' handles 'Amount', a value type, which isn't supported when running as Native AOT...")Evidence
AOT harness (.NET 10 Native AOT publish of a BatchProcessing app with
TrimmerRootAssembly, packed from this branch):BatchProcessing powertools=12 total=12BatchProcessing powertools=0 total=0Runtime check: a Native AOT app (no
TrimmerRootAssembly, 0 IL warnings) on the packed build. It processes SQS, Kinesis and DynamoDB Streams batches, each with a failing record (and a bad-JSON SQS record). It uses typed handlers (direct, provider, with context, provider with context) and a traditional handler. The output matches the same app under JIT line for line:Tests: new
NativeAot/NativeAotCompatibilityTests(simulated AOT throughRuntimeFeatureWrapper):dotnet test tests/AWS.Lambda.Powertools.BatchProcessing.Tests: 262/262 on net8.0 and 262/262 on net10.0.dotnet build --configuration Releasefromlibraries/succeeds with no IL warnings in BatchProcessing.Merge Danger
Door: two-way
Internal changes plus two widened
DynamicallyAccessedMembersannotations. Easy to revert.Blast Radius: BatchProcessing
ITypedBatchProcessor<,>instead of a publicProcessAsyncfound by reflection on the concrete type. This is the same for any processor that implements the interface normally.ITypedRecordHandlerWithContext<T>without anILambdaContextargument now throwsInvalidOperationExceptionwith guidance. Before,MethodInfo.Invokethrew anArgumentException.IsReflectionEnabledByDefault=false) without aJsonSerializerContextnow getAotCompatibilityExceptioninstead of STJ's "reflection-based serialization has been disabled" error.Checklist
Is this a breaking change?
No.
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.