Skip to content

⚡ Bolt: [performance improvement] Cache static schedule metadata at module scope - #66

Merged
nickdesi merged 1 commit into
mainfrom
bolt/cache-calendar-metadata-2021829896999145240
Aug 7, 2026
Merged

⚡ Bolt: [performance improvement] Cache static schedule metadata at module scope#66
nickdesi merged 1 commit into
mainfrom
bolt/cache-calendar-metadata-2021829896999145240

Conversation

@nickdesi

@nickdesi nickdesi commented Aug 6, 2026

Copy link
Copy Markdown
Owner

💡 What:
Replaced O(N) array scans (array.some() and loop for max value) in src/lib/gtfs-freshness.ts with O(1) Set lookups and a cached scalar value by pre-computing VALID_DATES and CALENDAR_END_DATE during module initialization.

🎯 Why:
The gtfs-freshness.ts functions (isCalendarValid, getCalendarEndDate) are called on every request to the /api/freshness endpoint. Iterating over the large imported staticSchedule.json array on every call is inefficient and burns unnecessary CPU cycles, especially under load.

📊 Impact:

  • Reduces the time complexity of checking calendar validity from O(N) to O(1) where N is the number of scheduled trips.
  • Eliminates repeated full-array scans when retrieving the calendar end date.
  • Significantly lowers CPU overhead and reduces request processing time for freshness checks.

🔬 Measurement:
Run the unit tests using npm run test and check /api/freshness response times under load. Memory usage should remain stable as the unique dates Set is small.


PR created automatically by Jules for task 2021829896999145240 started by @nickdesi

…odule scope

💡 What:
Replaced O(N) array scans (`array.some()` and loop for max value) in `src/lib/gtfs-freshness.ts` with O(1) `Set` lookups and a cached scalar value by pre-computing `VALID_DATES` and `CALENDAR_END_DATE` during module initialization.

🎯 Why:
The `gtfs-freshness.ts` functions (`isCalendarValid`, `getCalendarEndDate`) are called on every request to the `/api/freshness` endpoint. Iterating over the large imported `staticSchedule.json` array on every call is inefficient and burns unnecessary CPU cycles, especially under load.

📊 Impact:
- Reduces the time complexity of checking calendar validity from O(N) to O(1) where N is the number of scheduled trips.
- Eliminates repeated full-array scans when retrieving the calendar end date.
- Significantly lowers CPU overhead and reduces request processing time for freshness checks.

🔬 Measurement:
Run the unit tests using `npm run test` and check `/api/freshness` response times under load. Memory usage should remain stable as the unique dates Set is small.

Co-authored-by: nickdesi <38331055+nickdesi@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.

@github-actions github-actions Bot left a comment

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.

🤖 Revue automatique par l'IA (gemini-2.5-flash)

Verdict : ✅ Approuvé

Cette Pull Request apporte d'excellentes optimisations de performance en implémentant une stratégie de mise en cache au niveau du module pour les données statiques. Les opérations coûteuses en O(N) (scans d'arrays) sont remplacées par des recherches en O(1) (utilisation de Set et de variables précalculées), ce qui réduit considérablement la charge CPU et la pression sur le ramasse-miettes. La documentation associée dans .jules/bolt.md est claire et pertinente. Le code est plus performant et plus lisible. Aucun problème identifié, prêt à fusionner.

Revue générée automatiquement.

Comment thread src/lib/gtfs-freshness.ts
tripId: string;
}

// ⚡ Bolt: Cache calendar metadata at module scope to avoid O(N) array scans

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.

Excellente implémentation de la mise en cache au niveau du module. Cela transforme des opérations potentiellement coûteuses en O(N) en des recherches O(1) extrêmement performantes pour les fonctions isCalendarValid et getCalendarEndDate. C'est une optimisation majeure et très appréciée pour une route API ou un utilitaire fréquemment appelé.

@nickdesi
nickdesi merged commit 76e33a0 into main Aug 7, 2026
2 checks passed
@nickdesi
nickdesi deleted the bolt/cache-calendar-metadata-2021829896999145240 branch August 7, 2026 07:04
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