Skip to content

⚡ Optimize library update performance with parallel requests#34

Merged
Aatricks merged 1 commit intomainfrom
perf-library-updates-parallel-4624887405357361821
Feb 6, 2026
Merged

⚡ Optimize library update performance with parallel requests#34
Aatricks merged 1 commit intomainfrom
perf-library-updates-parallel-4624887405357361821

Conversation

@Aatricks
Copy link
Owner

@Aatricks Aatricks commented Feb 6, 2026

Optimize refreshLibraryUpdates to use parallel execution with a concurrency limit.

Changes:

  • Modified app/src/main/java/io/aatricks/novelscraper/data/repository/LibraryRepository.kt:
    • Wrapped the update loop in coroutineScope.
    • Used groupedItems.map { async { ... } }.awaitAll() to parallelize processing.
    • Introduced a Semaphore(5) to limit concurrent network requests to 5.
    • Added necessary imports (async, awaitAll, coroutineScope, Semaphore, withPermit).

Verification:

  • Verified with a temporary performance test (LibraryRepositoryPerformanceTest) simulating 10 novels with 100ms latency each.
    • Baseline (sequential): ~1000ms
    • Optimized (parallel): ~200ms
  • Verified existing tests (LibraryRepositoryTest) passed to ensure no regressions.

PR created automatically by Jules for task 4624887405357361821 started by @Aatricks

Refactored `refreshLibraryUpdates` in `LibraryRepository` to execute network requests concurrently using `async` and a `Semaphore` (limit 5). This replaces the previous sequential implementation, significantly reducing the total time required to check for updates across multiple novels.

Performance improvement:
- Sequential: O(N) where N is number of novels. Total time = Sum(request_time_i).
- Parallel: O(N/K) where K is concurrency limit (5). Total time ~ Max(request_time_batch) * (N/K).
- Measured ~5x speedup for 10 items with 100ms simulated latency (200ms vs 1000ms).

Co-authored-by: Aatricks <113598245+Aatricks@users.noreply.github.com>
@google-labs-jules
Copy link
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.

@Aatricks Aatricks merged commit c3dbe88 into main Feb 6, 2026
1 check passed
@Aatricks Aatricks self-assigned this Feb 6, 2026
@Aatricks Aatricks deleted the perf-library-updates-parallel-4624887405357361821 branch February 6, 2026 19:05
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