Skip to content

perf: memoize search regex in History to avoid per-cell RegExp creation - #593

Merged
gopaljilab merged 2 commits into
gopaljilab:mainfrom
nyxsky404:fix/highlight-text-memoize-regex
Jun 2, 2026
Merged

gopaljilab merged 2 commits into
gopaljilab:mainfrom
nyxsky404:fix/highlight-text-memoize-regex

Conversation

@nyxsky404

@nyxsky404 nyxsky404 commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

Memoizes the search regex in the History page so it's compiled once per search term change instead of once per table cell render. Previously, every HighlightText instance created its own RegExp on every render, resulting in hundreds of regex compilations per keystroke.

Related Issue

Fixes #581

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • 🎨 Style / UI improvement
  • ♻️ Refactor (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test addition or update
  • 🔧 Chore / Tooling / Config

Changes Made

  • Added useMemo to compile the search regex once per searchTerm change in the History component
  • Changed HighlightText to accept a pre-compiled searchRegex: RegExp | null prop instead of a raw search: string
  • Added try/catch around regex usage to gracefully handle edge cases
  • Updated all HighlightText usages to pass the memoized regex

Testing

  • I have tested these changes locally
  • All existing tests pass

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code where necessary
  • I have updated the documentation if needed

@github-actions github-actions Bot added gssoc:approved level:intermediate Requires standard familiarity with the codebase. type:bug Something isn't working or throwing errors. labels Jun 2, 2026
@gopaljilab
gopaljilab merged commit ab53fae into gopaljilab:main Jun 2, 2026
3 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved level:intermediate Requires standard familiarity with the codebase. type:bug Something isn't working or throwing errors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] HighlightText creates hundreds of RegExp instances per keystroke — performance issue

2 participants