Skip to content

Optimize external API calls#67

Merged
amrabed merged 7 commits into
mainfrom
bolt-graphql-list-optimization-4324119398292863746
Jun 7, 2026
Merged

Optimize external API calls#67
amrabed merged 7 commits into
mainfrom
bolt-graphql-list-optimization-4324119398292863746

Conversation

@amrabed

@amrabed amrabed commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Pull Request Type

  • Bug Fix
  • Feature
  • Optimization
  • Refactor
  • Documentation Update
  • Dependency Update

Summary

Optimize external API calls in the eventbridge template by using requests.Session

google-labs-jules Bot and others added 6 commits June 7, 2026 07:45
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.
@amrabed amrabed force-pushed the bolt-graphql-list-optimization-4324119398292863746 branch from 3638851 to 2df21ca Compare June 7, 2026 11:46
@amrabed amrabed marked this pull request as ready for review June 7, 2026 11:49
@amrabed amrabed changed the title Optimize external API calls in the eventbridge template Optimize external API calls Jun 7, 2026
@amrabed amrabed merged commit 05d0471 into main Jun 7, 2026
1 check passed
@amrabed amrabed deleted the bolt-graphql-list-optimization-4324119398292863746 branch June 7, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant