Skip to content

Conversation

@TrevorBurnham
Copy link
Contributor

Description

This PR optimizes the filterOptions utility in src/autosuggest/utils/utils.ts by applying three micro-optimizations:

  1. Hoist field arrays to module scope: Move searchableFields and searchableTagFields arrays outside the matchSingleOption function to avoid recreating them on every call
  2. Move toLowerCase() outside the filter loop: The search text is now lowercased once in filterOptions rather than on every matchSingleOption call
  3. Replace indexOf() !== -1 with includes(): More idiomatic and slightly faster for substring matching

The filterOptions function is called whenever:

  • A user types in an autosuggest input (with filteringType="auto")
  • The dropdown options need to be filtered based on the entered text

This is a hot path during user interaction, as filtering runs on every keystroke.

Micro-benchmarks show 10-25% improvement for typical filtering scenarios

How has this been tested?

Existing tests provide extensive coverage for this functionality.

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

- Move searchableFields and searchableTagFields arrays to module scope
  to avoid recreating them on every matchSingleOption call
- Move toLowerCase() call outside the filter loop to avoid repeated
  string operations
- Replace indexOf() !== -1 with includes() for cleaner, slightly faster
  string matching

Benchmarks show 10-25% improvement for typical filtering scenarios.
@TrevorBurnham TrevorBurnham requested a review from a team as a code owner January 25, 2026 15:18
@TrevorBurnham TrevorBurnham requested review from cansuaa and removed request for a team January 25, 2026 15:18
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.

1 participant