Skip to content

⚡ Bolt: Optimize global helper regex performance#96

Merged
bartholomej merged 1 commit intomasterfrom
bolt-optimize-global-helper-regex-8514671053990654241
Feb 26, 2026
Merged

⚡ Bolt: Optimize global helper regex performance#96
bartholomej merged 1 commit intomasterfrom
bolt-optimize-global-helper-regex-8514671053990654241

Conversation

@bartholomej
Copy link
Owner

@bartholomej bartholomej commented Feb 25, 2026

⚡ Bolt: [performance improvement]

💡 What: Hoisted LANG_PREFIX_REGEX and ISO8601_DURATION_REGEX to module-level constants in src/helpers/global.helper.ts.
🎯 Why: parseIdFromUrl and parseISO8601Duration created new RegExp objects on every call. These are hot paths used frequently during scraping.
📊 Impact: ~10% faster execution for parseIdFromUrl in benchmarks (from ~1100ms to ~986ms for 5M iterations).
🔬 Measurement: Verified with a local benchmark script (bench.ts) running 5M iterations. Correctness verified with yarn test.


PR created automatically by Jules for task 8514671053990654241 started by @bartholomej

Summary by CodeRabbit

  • Refactor
    • Improved internal code organization and maintainability through regex pattern consolidation. No changes to end-user functionality or features.

Extracted `LANG_PREFIX_REGEX` and `ISO8601_DURATION_REGEX` to module-level constants to avoid recompilation on every function call.

- Benchmarks show ~10% improvement in `parseIdFromUrl`.
- Reduces GC pressure.

Co-authored-by: bartholomej <5861310+bartholomej@users.noreply.github.com>
@google-labs-jules
Copy link
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

coderabbitai bot commented Feb 25, 2026

📝 Walkthrough

Walkthrough

Two inline regex patterns in global.helper.ts were extracted into reusable constants: LANG_PREFIX_REGEX and ISO8601_DURATION_REGEX. These constants replace direct regex usage in parseIdFromUrl and parseISO8601Duration functions, improving maintainability without altering behavior.

Changes

Cohort / File(s) Summary
Regex Constants Extraction
src/helpers/global.helper.ts
Extracted two inline regex patterns into named constants (LANG_PREFIX_REGEX for language prefix detection in parseIdFromUrl and ISO8601_DURATION_REGEX for ISO8601 duration parsing). No functional changes to matching logic or downstream operations.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Constants hop where patterns lay,
No more magic strings at play,
Regex reborn, now clearly named,
Maintainability proclaimed! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides context, motivation, and measurement results, but does not follow the required template structure with sections like 'Type of change' and 'Checklist'. Use the repository's description template with required sections: Description, Type of change (checkboxes), Related Issues, and Checklist items.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main change: hoisting regex patterns to module-level constants for performance optimization in the global helper.
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-global-helper-regex-8514671053990654241

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

@codecov-commenter
Copy link

⚠️ 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 (b5cb094) to head (c813f57).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #96   +/-   ##
=======================================
  Coverage   99.21%   99.21%           
=======================================
  Files          28       28           
  Lines         635      636    +1     
  Branches      145      145           
=======================================
+ Hits          630      631    +1     
  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.

Copy link

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/helpers/global.helper.ts`:
- Around line 67-69: Guard against null regex matches from
iso.match(ISO8601_DURATION_REGEX) before calling getDuration: check whether
matches is truthy (e.g., if (!matches) ...) and handle the malformed/no-match
case (return a safe default duration or null, or throw a controlled error)
instead of directly calling getDuration(matches); update the code around the
iso, ISO8601_DURATION_REGEX and getDuration usage to use this null check (or
optional chaining/try-catch inside getDuration) so malformed scrape data cannot
cause a runtime error.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5cb094 and c813f57.

📒 Files selected for processing (1)
  • src/helpers/global.helper.ts

Comment on lines +67 to 69
const matches = iso.match(ISO8601_DURATION_REGEX);

const duration = getDuration(matches);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Guard against null regex matches before calling getDuration.

iso.match(...) can return null; on Line 69 that becomes a runtime error in malformed scrape data paths.

Suggested fix
 export const parseISO8601Duration = (iso: string): number => {
   const matches = iso.match(ISO8601_DURATION_REGEX);
+  if (!matches) return 0;
 
   const duration = getDuration(matches);
 
   return +duration.hours * 60 + +duration.minutes;
 };

As per coding guidelines, "Never assume an element exists. CSFD changes layouts. Use optional chaining ?. or try/catch inside helpers for robust scraping."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/helpers/global.helper.ts` around lines 67 - 69, Guard against null regex
matches from iso.match(ISO8601_DURATION_REGEX) before calling getDuration: check
whether matches is truthy (e.g., if (!matches) ...) and handle the
malformed/no-match case (return a safe default duration or null, or throw a
controlled error) instead of directly calling getDuration(matches); update the
code around the iso, ISO8601_DURATION_REGEX and getDuration usage to use this
null check (or optional chaining/try-catch inside getDuration) so malformed
scrape data cannot cause a runtime error.

@bartholomej bartholomej merged commit c813f57 into master Feb 26, 2026
2 checks passed
@bartholomej bartholomej deleted the bolt-optimize-global-helper-regex-8514671053990654241 branch February 26, 2026 08:05
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