Skip to content

⚡ Bolt: Optimize helper functions to reduce object allocation#93

Closed
bartholomej wants to merge 1 commit intomasterfrom
bolt-optimize-helpers-6826399796074699989
Closed

⚡ Bolt: Optimize helper functions to reduce object allocation#93
bartholomej wants to merge 1 commit intomasterfrom
bolt-optimize-helpers-6826399796074699989

Conversation

@bartholomej
Copy link
Copy Markdown
Owner

@bartholomej bartholomej commented Feb 23, 2026

💡 What: Extracted CREATOR_LABELS and iso8601DurationRegex to 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

  • Refactor
    • Optimized performance by eliminating unnecessary repeated data structure allocations during runtime operations.
    • Consolidated static data structures to reduce garbage collection pressure and improve overall application efficiency.

- 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>
@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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 23, 2026

📝 Walkthrough

Walkthrough

The PR optimizes performance by hoisting constant data structures from function-local scope to module-level scope in two helper functions. A regex pattern in global.helper.ts and a localized creator labels map in movie.helper.ts are moved to avoid repeated large object allocations during execution. Documentation updates codify this optimization pattern.

Changes

Cohort / File(s) Summary
Documentation
.jules/bolt.md
Added performance optimization guidance recommending that helper functions hoist constant data structures outside function scope to reduce GC pressure.
Helper Function Optimization
src/helpers/global.helper.ts
Hoisted iso8601DurationRegex from function-local to module-level constant scope while preserving parseISO8601Duration function behavior.
Creator Labels Centralization
src/helpers/movie.helper.ts
Extracted CREATOR_LABELS map containing localized creator group labels (en, cs, sk) to module scope; getLocalizedCreatorLabel now references this centralized structure instead of inline lookup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 Constants hop outside their nest,
No more rebirth, they rest and rest,
The garbage collector takes a break,
While helper functions run awake! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains what was changed and why, but omits required template sections like Type of change, Related Issues, and Checklist. Complete the pull request description by adding the missing required sections: Type of change (select Refactoring), Related Issues (link issue 6826399796074699989), and Checklist items.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and concisely describes the main optimization objective: moving helper function constants to reduce object allocation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bolt-optimize-helpers-6826399796074699989

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.

Copy link
Copy Markdown

@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

🧹 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 considers CREATOR_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.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a6b082 and cb1ff46.

📒 Files selected for processing (3)
  • .jules/bolt.md
  • src/helpers/global.helper.ts
  • src/helpers/movie.helper.ts

@@ -0,0 +1,3 @@
## 2025-02-23 - Helper Function Object Allocation
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.21%. Comparing base (6a6b082) to head (cb1ff46).
⚠️ Report is 2 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bartholomej bartholomej deleted the bolt-optimize-helpers-6826399796074699989 branch March 20, 2026 22:49
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.

2 participants