Optimize external API calls#67
Merged
Merged
Conversation
Replaced individual `requests.get` calls with a persistent `requests.Session` in the `Handler` class. In AWS Lambda, using a persistent session enables TCP and TLS connection pooling across warm starts. This significantly reduces latency by avoiding the overhead of repeated handshakes (approx. 50-200ms per call depending on distance and TLS complexity). Also optimized JSON parsing by using `ApiResponse.model_validate_json` on raw bytes (`response.content`), leveraging Pydantic's Rust core. Changes: - Updated `Handler.__init__` to instantiate `requests.Session`. - Refactored `handle` method to use `self._session.get`. - Updated `ApiResponse` validation to use `model_validate_json`. - Updated unit and property-based tests to mock the session object.
Optimized the EventBridge API caller template for high-performance Lambda execution. 1. Connection Pooling: Replaced standalone `requests.get` calls with a persistent `requests.Session` in the `Handler` class. This enables TCP/TLS connection reuse across warm starts, reducing latency by ~50-200ms per call. 2. Fast Parsing: Switched to `ApiResponse.model_validate_json` using `response.content` (raw bytes). This bypasses Python's dictionary creation in `response.json()` and leverages Pydantic's Rust-based parser. 3. Journaling: Added a BOLT performance journal in `.jules/bolt.md` to document these patterns. Tests have been updated to mock the session object correctly.
3638851 to
2df21ca
Compare
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.
Pull Request Type
Summary
Optimize external API calls in the eventbridge template by using
requests.Session