Skip to content

[RFC] [Autocomplete] performance improvement #47843

@mariia-mitiureva

Description

@mariia-mitiureva

What's the problem?

When using Autocomplete with a large number of options (e.g. 10,000 items as in the example from the docs), the component becomes noticeably laggy in multiple mode, even with virtualization.

Here's the recording from Mac M2 Pro with CPU 4x slowdown:

Screen.Recording.2026-02-23.at.16.14.08.mov

Code sandbox - https://codesandbox.io/p/sandbox/mui-autocomplete-perf-qpkpsy

You can see that

  • "Select all" is slow, but unselect all is fast
  • Typing in the input is slow when all options selected, but fast when no option selected

So performance depends on the number of selected options.

What are the requirements?

Autocomplete should remain responsive and provide smooth user interaction when used with a large dataset in multiple mode and virtualization applied.

What are our options?

No response

Proposed solution

getOptionProps inside useAutocomplete internally calls [value].some(). And since getOptionProps is called for every option we get O(n^2) when all options are selected.

My proposal is to add a new prop isOptionSelected to let users define if an option is selected or not. I tested it, and when I use Set.has() instead of Array.some(), it significantly improves performance, so I almost don't feel any delay with my setup.

Image

Alternatively, material-ui could use Set internally, but it wouldn't work when isOptionEqualToValue is provided and doesn't use reference equality.

Additionally, it makes sense to move filterSelectedOptions condition outside of filter function, but that's not the main problem here.

Image

Resources and benchmarks

No response

Search keywords:

Metadata

Metadata

Labels

RFCRequest For Comments.scope: autocompleteChanges related to the autocomplete. This includes ComboBox.status: waiting for maintainerThese issues haven't been looked at yet by a maintainer.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions