generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 497
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Problem Statement
Summary
Optimize S3SessionManager.list_messages() to retrieve message files from S3 in parallel instead of sequentially, significantly improving performance for sessions with many messages.
Problem
Currently, list_messages() loads message files one at a time:
for key in message_keys:
message_data = self._read_s3_object(key) # Sequential - slow!Performance Impact:
- 100 messages × 50ms latency = ~5 seconds
- Network I/O bottleneck: each request waits for the previous to complete
Proposed Solution
Solution
Use ThreadPoolExecutor to fetch multiple S3 objects concurrently:
with ThreadPoolExecutor(max_workers=None) as executor:
future_to_key = {executor.submit(self._read_s3_object, key): key
for key in message_keys}
# Process results as they complete, maintaining orderPerformance Improvement:
- 100 messages in parallel = ~50-200ms
- 10-100x speedup for large message histories
Implementation
- ✅ Added
concurrent.futuresimports - ✅ Parallelized
list_messages()usingThreadPoolExecutor - ✅ Maintains message order (sorts by original index)
- ✅ Graceful error handling (individual failures don't stop operation)
- ✅ Backward compatible (no API changes)
Testing Checklist
- Test with various message counts (1, 10, 100, 1000)
- Verify message order is preserved
- Test error handling (missing files, network errors)
- Performance benchmarks (before/after comparison)
Use Case
any session with 5+ turns can see increased latency
Alternatives Solutions
No response
Additional Context
No response
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request