⚡ Bolt: [performance improvement] Cache static schedule metadata at module scope - #66
Conversation
…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>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
🤖 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.
| tripId: string; | ||
| } | ||
|
|
||
| // ⚡ Bolt: Cache calendar metadata at module scope to avoid O(N) array scans |
There was a problem hiding this comment.
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é.
💡 What:
Replaced O(N) array scans (
array.some()and loop for max value) insrc/lib/gtfs-freshness.tswith O(1)Setlookups and a cached scalar value by pre-computingVALID_DATESandCALENDAR_END_DATEduring module initialization.🎯 Why:
The
gtfs-freshness.tsfunctions (isCalendarValid,getCalendarEndDate) are called on every request to the/api/freshnessendpoint. Iterating over the large importedstaticSchedule.jsonarray on every call is inefficient and burns unnecessary CPU cycles, especially under load.📊 Impact:
🔬 Measurement:
Run the unit tests using
npm run testand check/api/freshnessresponse 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