Skip to content

⚡ Parallelize sequential API requests in AddMediaModal#72

Merged
AJFrio merged 1 commit into
mainfrom
perf-parallelize-media-uploads-3930785246201435280
Jun 15, 2026
Merged

⚡ Parallelize sequential API requests in AddMediaModal#72
AJFrio merged 1 commit into
mainfrom
perf-parallelize-media-uploads-3930785246201435280

Conversation

@AJFrio

@AJFrio AJFrio commented Jun 15, 2026

Copy link
Copy Markdown
Owner

This PR optimizes the AddMediaModal component by parallelizing independent network requests that were previously being executed sequentially.

💡 What:

  • Replaced for...of loops that awaited each iteration with Promise.all and .map().
  • Added a benchmark script to measure and verify the impact.

🎯 Why:
The previous implementation was a classic anti-pattern where each file upload or reference image fetch had to wait for the previous one to complete, leading to linear wait times (O(N)). Concurrent execution allows these I/O-bound tasks to overlap, significantly improving perceived performance.

📊 Measured Improvement:
Using the included benchmark script (benchmarks/add-media-modal-upload.js) with simulated 100ms upload and 50ms media recording delays:

  • Sequential (5 files): ~807ms
  • Parallel (5 files): ~162ms
  • Improvement: ~80% reduction in total execution time.

PR created automatically by Jules for task 3930785246201435280 started by @AJFrio

Optimize the media upload and reference image fetching processes by replacing sequential `for...of` loops with `Promise.all`. This allows multiple network requests to be executed concurrently, significantly reducing wait time for users.

- Refactored `uploadFileAndRecord` to use `Promise.all` for file processing and uploads.
- Refactored `generateImage` to use `Promise.all` for fetching reference images.
- Added `benchmarks/add-media-modal-upload.js` to establish and verify performance gains (~80% improvement simulated).

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@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.

@AJFrio AJFrio merged commit a292f96 into main Jun 15, 2026
2 checks passed
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