Skip to content

⚡ Bolt: Use shared httpx.AsyncClient for concurrent uploads#54

Open
kourdroid wants to merge 1 commit into
mainfrom
bolt/supabase-storage-shared-client-12198355291564608865
Open

⚡ Bolt: Use shared httpx.AsyncClient for concurrent uploads#54
kourdroid wants to merge 1 commit into
mainfrom
bolt/supabase-storage-shared-client-12198355291564608865

Conversation

@kourdroid

Copy link
Copy Markdown
Owner

💡 What:
Updated SupabaseStorage to accept an optional httpx.AsyncClient in its upload and download methods. In src/api/routes.py, an httpx.AsyncClient is instantiated and shared across all concurrent file uploads in asyncio.gather.

🎯 Why:
Previously, a new httpx.AsyncClient was instantiated for every split file upload during ingestion. This incurred expensive TCP and TLS handshakes for each HTTP request, creating a performance bottleneck when handling documents with many splits. Attempting to use a request-scoped class context manager (__aenter__) could cause race conditions, so passing the client explicitly is safer.

📊 Impact:
Significantly reduces I/O latency and CPU overhead during PDF split processing. For multi-split PDFs, the total ingest time is expected to drop by eliminating N round-trip handshakes to Supabase storage.

🔬 Measurement:
Profile the latency of the /ingest route when uploading a multi-page PDF (e.g., > 10 pages). Observe the reduction in connection establishment overhead in logging or tracing. The behavior has been verified with existing unit tests.


PR created automatically by Jules for task 12198355291564608865 started by @kourdroid

Refactored `SupabaseStorage.upload` and `download` methods to accept an optional `httpx.AsyncClient` parameter. Updated the `ingest` route to instantiate an `httpx.AsyncClient` inside an `async with` context block and pass it to the concurrent file upload calls. This eliminates repeated TCP/TLS handshake overhead while preventing race conditions by not mutating instance state. Mocks in tests were updated accordingly.

Co-authored-by: kourdroid <36898160+kourdroid@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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