Skip to content

Conversation

@dcabib
Copy link

@dcabib dcabib commented Feb 2, 2026

Description

Implements automatic class preloading via CRaC hooks for the powertools-idempotency-dynamodb module to improve SnapStart cold start performance.

This PR adds automatic priming support to complement the existing invoke priming that was implemented in #1861.

Changes

  • ✅ Add ClassPreLoader.preloadClasses() call to DynamoDBPersistenceStore.beforeCheckpoint()
  • ✅ Generate and include classesloaded.txt with 8,726 classes
  • ✅ Add powertools-common dependency for ClassPreLoader
  • ✅ Add Maven profile generate-classesloaded-file for regenerating the classes file
  • ✅ Add unit tests for CRaC hooks (beforeCheckpoint() and afterRestore())
  • ✅ Update Priming.md with idempotency-dynamodb example
  • ✅ Add null check and logging for defensive error handling

Implementation Details

This implementation combines both priming strategies:

  1. Invoke priming (already existed): Exercises DynamoDB SDK paths with PUT/GET/DELETE operations
  2. Automatic priming (new): Preloads 8,726 classes from classesloaded.txt during SnapStart checkpoint

The combined approach ensures optimal cold start performance by:

  • Warming up DynamoDB client connection pools
  • Preloading all necessary classes into memory
  • Exercising critical code paths before the snapshot is taken

Pattern Consistency

Follows the same pattern as implemented in:

Key differences justified for persistence layer:

  • Exception handling: Wraps priming in try-catch to ensure checkpoint never fails (critical for persistence operations)
  • Null check: Guards against disabled idempotency scenario
  • Logging: Logs exceptions for debugging while maintaining fail-safe behavior

Testing

  • ✅ Unit tests pass: testBeforeCheckpointDoesNotThrowException() and testAfterRestoreDoesNotThrowException()
  • ✅ Example application builds successfully
  • ✅ All existing tests continue to pass

Verification

To verify this works with SnapStart:

  1. Deploy a Lambda function with SnapStart enabled using idempotency-dynamodb
  2. Check CloudWatch Logs for priming execution during INIT phase
  3. Observe reduced cold start times compared to non-primed deployments

Related Issues

Fixes #1997

Maintainer Confirmation

As confirmed by @phipag in #1997 (comment):

"Option 1 sounds good. Only add it in -dynamodb for now."


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Implements automatic class preloading via CRaC hooks for the
idempotency-dynamodb module to improve SnapStart cold start performance.

Changes:
- Add ClassPreLoader.preloadClasses() call to DynamoDBPersistenceStore.beforeCheckpoint()
- Generate and include classesloaded.txt with 8,726 classes
- Add powertools-common dependency for ClassPreLoader
- Add Maven profile generate-classesloaded-file
- Add unit tests for CRaC hooks
- Update Priming.md with idempotency-dynamodb example
- Add null check and logging for defensive error handling

This combines both invoke priming (warming DynamoDB SDK paths)
and automatic priming (preloading classes) for optimal performance.

Follows the same pattern as implemented in powertools-metrics (aws-powertools#1861),
powertools-tracing (aws-powertools#2345), and powertools-kafka (aws-powertools#2145).

Fixes aws-powertools#1997

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 2, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Priming for powertools-idempotency

1 participant