⚡ Bolt: Optimize helper functions to reduce object allocation#93
⚡ Bolt: Optimize helper functions to reduce object allocation#93bartholomej wants to merge 1 commit intomasterfrom
Conversation
- Moved `CREATOR_LABELS` to module scope in `movie.helper.ts` to avoid re-creation on every call. - Moved `iso8601DurationRegex` to module scope in `global.helper.ts` to avoid re-compilation on every call. - Verified with `yarn test run`. Co-authored-by: bartholomej <5861310+bartholomej@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. |
📝 WalkthroughWalkthroughThe PR optimizes performance by hoisting constant data structures from function-local scope to module-level scope in two helper functions. A regex pattern in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/helpers/movie.helper.ts (1)
21-24: Optional: narrow outer key type to'en' | 'cs' | 'sk'for clearer intent
Record<string, …>means TypeScript considersCREATOR_LABELS[anyString]as always defined, so the|| CREATOR_LABELS['cs']guard on line 96 is invisible to the type checker. Narrowing the outer key makes the supported locales explicit and removes the false-non-nullable typing, at the cost of a cast at the lookup site.♻️ Proposed type narrowing
-const CREATOR_LABELS: Record< - string, - Record<string, CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak> -> = { +const CREATOR_LABELS: Partial< + Record<'en' | 'cs' | 'sk', Record<string, CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak>> +> = {Then in
getLocalizedCreatorLabel:- return (CREATOR_LABELS[lang] || CREATOR_LABELS['cs'])[key]; + return (CREATOR_LABELS[lang as 'en' | 'cs' | 'sk'] ?? CREATOR_LABELS['cs']!)[key];🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/helpers/movie.helper.ts` around lines 21 - 24, The CREATOR_LABELS outer key is typed as Record<string,...> which hides missing-locale cases; change its type to Record<'en' | 'cs' | 'sk', Record<string, CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak>> so supported locales are explicit, then update getLocalizedCreatorLabel to use that narrower key type (and if necessary cast the incoming locale to 'en'|'cs'|'sk' at the lookup site) and keep the existing fallback (|| CREATOR_LABELS['cs']) — this makes the type checker aware of missing keys and removes the false non-nullability.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.jules/bolt.md:
- Line 1: Update the dated heading "2025-02-23 - Helper Function Object
Allocation" to use the correct year; change "2025" to "2026" so the header reads
"2026-02-23 - Helper Function Object Allocation" in the .jules/bolt.md file.
---
Nitpick comments:
In `@src/helpers/movie.helper.ts`:
- Around line 21-24: The CREATOR_LABELS outer key is typed as Record<string,...>
which hides missing-locale cases; change its type to Record<'en' | 'cs' | 'sk',
Record<string, CSFDCreatorGroups | CSFDCreatorGroupsEnglish |
CSFDCreatorGroupsSlovak>> so supported locales are explicit, then update
getLocalizedCreatorLabel to use that narrower key type (and if necessary cast
the incoming locale to 'en'|'cs'|'sk' at the lookup site) and keep the existing
fallback (|| CREATOR_LABELS['cs']) — this makes the type checker aware of
missing keys and removes the false non-nullability.
| @@ -0,0 +1,3 @@ | |||
| ## 2025-02-23 - Helper Function Object Allocation | |||
There was a problem hiding this comment.
Year typo: 2025 should be 2026
📝 Proposed fix
-## 2025-02-23 - Helper Function Object Allocation
+## 2026-02-23 - Helper Function Object Allocation🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.jules/bolt.md at line 1, Update the dated heading "2025-02-23 - Helper
Function Object Allocation" to use the correct year; change "2025" to "2026" so
the header reads "2026-02-23 - Helper Function Object Allocation" in the
.jules/bolt.md file.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #93 +/- ##
=======================================
Coverage 99.21% 99.21%
=======================================
Files 28 28
Lines 635 635
Branches 145 145
=======================================
Hits 630 630
Misses 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
💡 What: Extracted
CREATOR_LABELSandiso8601DurationRegexto top-level constants.🎯 Why: To prevent re-creating large objects and re-compiling regexes on every function call (which happens multiple times per movie).
📊 Impact: Reduces memory allocation churn and regex compilation overhead in hot paths.
🔬 Measurement: Verified with
yarn test run(no regressions).PR created automatically by Jules for task 6826399796074699989 started by @bartholomej
Summary by CodeRabbit