Skip to content

⚡ Parallelize data fetching in generateStaticParams#32

Closed
anyulled wants to merge 4 commits into
mainfrom
perf/generate-static-params-parallel-11884188078307938376
Closed

⚡ Parallelize data fetching in generateStaticParams#32
anyulled wants to merge 4 commits into
mainfrom
perf/generate-static-params-parallel-11884188078307938376

Conversation

@anyulled
Copy link
Copy Markdown
Owner

@anyulled anyulled commented Feb 8, 2026

This PR optimizes generateStaticParams in app/[year]/talks/[talk_id]/page.tsx by replacing sequential data fetching with parallel fetching using Promise.all.

💡 What

  • Changed the for loop that iterates over years to Promise.all with map.
  • Included a benchmark test __tests__/performance_generate_static_params.test.ts to verify the performance gain.

🎯 Why

Fetching data sequentially for each year is inefficient and slows down the build process (or dynamic generation). Parallelizing these requests significantly reduces the total time.

📊 Measured Improvement

Using a benchmark test with a simulated 100ms delay per request for 4 years:

  • Baseline (Sequential): ~400ms
  • Optimized (Parallel): ~100ms
  • Speedup: ~4x faster

All existing tests passed. package-lock.json changes were reverted to ensure clean history.


PR created automatically by Jules for task 11884188078307938376 started by @anyulled

Summary by CodeRabbit

  • Refactor
    • Optimized page parameter generation to use parallel execution for improved performance.
  • Tests
    • Added performance testing for static parameter generation.
  • Style
    • Applied code formatting and whitespace adjustments across multiple files.
  • Chores
    • Updated code formatting configuration and removed unused imports.

Refactor `generateStaticParams` to fetch talk data for all years in parallel using `Promise.all`.
This reduces the build/generation time significantly compared to the sequential loop.

Benchmark results (simulated 100ms network delay per request, 4 years):
- Sequential: ~400ms
- Parallel: ~100ms
- Improvement: ~4x faster in this scenario.

Added `__tests__/performance_generate_static_params.test.ts` to verify the performance improvement and prevent regression.

Co-authored-by: anyulled <100741+anyulled@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.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
devbcn Ready Ready Preview, Comment Feb 8, 2026 5:11pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 8, 2026

Warning

Rate limit exceeded

@anyulled has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 37 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

The PR performs whitespace cleanup across test and page files, adds Prettier ignore patterns for agent files, refactors generateStaticParams to use parallel Promise.all execution instead of sequential processing, introduces a performance test, and adjusts code indentation in multiple components.

Changes

Cohort / File(s) Summary
Configuration & Formatting
.prettierignore, __tests__/pages/job-offers.test.tsx, __tests__/pages/speaker-detail.test.tsx, app/conditions/page.tsx, app/kcd/page.tsx, components/sections/faq/FaqContent.tsx
Add .agent and .agents patterns to Prettier ignore rules; remove leading/trailing blank lines from test files and page components.
Performance Test Suite
__tests__/performance_generate_static_params.test.ts
New test file validating generateStaticParams performance and correctness with mocked Next.js modules and talks API; asserts 100–300ms execution time indicating parallel operation.
generateStaticParams Optimization
app/[year]/talks/[talk_id]/page.tsx
Refactor from sequential per-year loop to parallelized Promise.all approach; fetch talks concurrently across years with per-year error handling and result flattening.
Code Indentation & Structure Refactoring
components/elements/AboutCounter.tsx, types/index.ts, context/ScheduleContext.tsx
Adjust indentation/spacing in AboutCounter and type definitions; remove unused import and interface declaration from ScheduleContext.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant generateStaticParams
    participant Promise.all
    participant getTalks as getTalks (per-year)
    
    Caller->>generateStaticParams: generateStaticParams()
    generateStaticParams->>Promise.all: map years → Promise array
    par Parallel Year Processing
        Promise.all->>getTalks: fetch talks for 2023
        Promise.all->>getTalks: fetch talks for 2024
        Promise.all->>getTalks: fetch talks for 2025
        Promise.all->>getTalks: fetch talks for 2026
    and
        getTalks-->>Promise.all: return talks (100ms each)
        getTalks-->>Promise.all: return talks (100ms each)
        getTalks-->>Promise.all: return talks (100ms each)
        getTalks-->>Promise.all: return talks (100ms each)
    end
    Promise.all->>generateStaticParams: aggregate results
    generateStaticParams->>generateStaticParams: flatten & return params
    generateStaticParams-->>Caller: { year, talk_id }[]
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 With whiskers twitching, I celebrate today,
Parallel promises fetch talks the speedy way,
Blank lines removed, the code now sleek,
Tests ensure performance peaks,
Agent files hidden, formatting's neat!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: parallelizing data fetching in generateStaticParams, which is the primary optimization in this PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch perf/generate-static-params-parallel-11884188078307938376

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @anyulled, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing the efficiency of static parameter generation by transitioning from a sequential data retrieval mechanism to a parallel one. This fundamental shift in how data is fetched for different years aims to drastically cut down processing times, making the application more responsive during build or dynamic rendering phases.

Highlights

  • Performance Optimization: The generateStaticParams function in app/[year]/talks/[talk_id]/page.tsx has been optimized to fetch data in parallel using Promise.all instead of sequential for loops. This change significantly reduces the time required for data fetching, leading to faster build or dynamic generation processes.
  • New Performance Benchmark Test: A new benchmark test, __tests__/performance_generate_static_params.test.ts, has been added to validate the performance gains. This test simulates network delays and confirms that the parallelized approach is approximately 4 times faster than the previous sequential method.
  • Improved Error Handling: The parallelized data fetching now includes try-catch blocks within each Promise to gracefully handle failures for individual years, logging warnings without halting the entire process.
Changelog
  • tests/performance_generate_static_params.test.ts
    • Added a new performance test file to benchmark the generateStaticParams function.
    • Implemented mocks for getTalks to simulate asynchronous data fetching with a delay.
    • Included assertions to verify the correctness of generated parameters and the expected performance improvement (duration between 100ms and 300ms for 4 simulated requests).
  • app/[year]/talks/[talk_id]/page.tsx
    • Refactored the generateStaticParams function to replace the sequential for loop with Promise.all and map for parallel data fetching.
    • Modified the logic to collect and flatten results from parallel promises, ensuring all talk parameters are correctly aggregated.
    • Introduced error handling within the parallel map operation to log warnings for failed year fetches without stopping the entire process.
Activity
  • The pull request was automatically generated by Jules for a specific task.
  • A new performance test was introduced to validate the changes.
  • Existing tests passed, indicating no regressions from the refactoring.
  • Changes to package-lock.json were reverted to maintain a clean history.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively parallelizes data fetching in generateStaticParams using Promise.all, which is a great performance improvement for the build process. The implementation is correct and includes proper error handling. The addition of a new performance test to verify the optimization is excellent practice. I've added a couple of suggestions to improve the accuracy and strictness of the new test file.

Comment thread __tests__/performance_generate_static_params.test.ts
Comment thread __tests__/performance_generate_static_params.test.ts
Refactor `generateStaticParams` to fetch talk data for all years in parallel using `Promise.all`.
This reduces the build/generation time significantly compared to the sequential loop.

Benchmark results (simulated 100ms network delay per request, 4 years):
- Sequential: ~400ms
- Parallel: ~100ms
- Improvement: ~4x faster in this scenario.

Added `__tests__/performance_generate_static_params.test.ts` to verify the performance improvement and prevent regression.

Also fixed existing formatting issues:
- Added `.agent` and `.agents` to `.prettierignore` to prevent CI failures.
- Formatted `app/conditions/page.tsx`, `app/kcd/page.tsx` and other source files.

Co-authored-by: anyulled <100741+anyulled@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@__tests__/performance_generate_static_params.test.ts`:
- Around line 40-83: The test assumes a fixed list of years but doesn't mock
getAvailableEditions(), so generateStaticParams() may use the real editions and
break the assertions; update the test setup (beforeEach) to mock
getAvailableEditions (the import from "@/config/editions") to return the same
array assigned to years (["2023","2024","2025","2026"]) so
generateStaticParams() uses the controlled editions, then keep the existing mock
for getTalks and the assertions against params and timing.
🧹 Nitpick comments (2)
__tests__/performance_generate_static_params.test.ts (2)

79-82: Timing-based assertions are inherently flaky in CI.

expect(duration).toBeLessThan(300) and expect(duration).toBeGreaterThanOrEqual(100) rely on wall-clock time, which is unreliable under CI load. A better approach would be to use jest.useFakeTimers() or simply verify that getTalks was called for all years concurrently (e.g., assert all calls started before any resolved) rather than measuring elapsed time.

If you want to keep a timing-based smoke test, at minimum loosen the upper bound significantly (e.g., 1000ms) to avoid flaky failures.


1-2: Unused local years — consider deriving assertions from the mock.

The years constant on Line 41 is only used for params.length on Line 69. Since getAvailableEditions isn't mocked (see above), there's no guarantee these stay in sync. Once you mock getAvailableEditions, derive years from the same source or reference the mock's return value directly.

Comment thread __tests__/performance_generate_static_params.test.ts

// Assert parallel execution (roughly 100ms)
// It should be faster than sequential (400ms)
expect(duration).toBeLessThan(300);
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In @__tests__/performance_generate_static_params.test.ts around lines 40 - 83,
The test assumes a fixed list of years but doesn't mock getAvailableEditions(),
so generateStaticParams() may use the real editions and break the assertions;
update the test setup (beforeEach) to mock getAvailableEditions (the import from
"@/config/editions") to return the same array assigned to years
(["2023","2024","2025","2026"]) so generateStaticParams() uses the controlled
editions, then keep the existing mock for getTalks and the assertions against
params and timing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the catch! I have updated the test to mock getAvailableEditions to return the fixed list of years ['2023', '2024', '2025', '2026'], ensuring the test assertions remain valid regardless of changes to the real editions configuration.

- Updated `__tests__/performance_generate_static_params.test.ts` to mock `getAvailableEditions` from `@/config/editions`.
- This ensures the test remains deterministic and doesn't rely on the real configuration, preventing potential failures if the configuration changes (e.g., number of years).
- Addresses PR feedback.

Co-authored-by: anyulled <100741+anyulled@users.noreply.github.com>
@anyulled anyulled added the duplicate This issue or pull request already exists label May 25, 2026
@anyulled
Copy link
Copy Markdown
Owner Author

Closing as duplicate of #210.

@anyulled anyulled closed this May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant