Repository navigation
Autocomplete component performance fix - #739
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
NJevric
approved these changes
Nov 19, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #728.
Problem
In
multiplemode,isSelected()scanned the whole selection withequals()for every rendered suggestion, about 4 times per row (aria-selected,data-p-selected, the selected class and the PT context). With a large selection, opening the overlay and moving through it took seconds.onOptionSelectRange()and finding the selected option on open had the same scan.Changes
isSelected()looks values up in a cachedSet(computedselectedKeys). The Set is rebuilt only when the selection changes. Keys follow the existing equality rules: the value itself, the object reference, or thedataKeyfield.onOptionSelectRange(),findSelectedOptionIndex()and the next/previous selected lookups use the same lookup, so they no longer scan the selection for every suggestion.dataKeykeep a deep-equality fallback, so equal copies still match, such as the same items returned by a new search.isEqualsstill have their rule applied.dataKeyfor large object selections, and the Multiple section explains which in-place changes AutoComplete picks up.Results
Reproducer page, 5,000 string suggestions, virtual scroller off, median of 5 runs. Each step compares an AutoComplete with nothing selected against one with all suggestions selected. The overlay part is the open time minus the time to re-render the selected chips with the overlay closed:
With everything selected, the overlay part now takes 720 ms against 608 ms with nothing selected, and hovering costs the same as with nothing selected, so a large selection now costs about the same as an empty one. The rest of the open time is the selected chips re-rendering (about 430–460 ms in both versions), which grows linearly with the selection and isn't part of this issue.
Opening with 2,000 suggestions selected by reference (measured in vitest): 25.1 s before, 1.8 s after.
Behavior notes
dataKeyare still compared by deep equality when they aren't the same objects as the selected values, so they're as slow as before. This is documented.shallowReformarkRawvalue array are no longer picked up. Assign a new array instead. This is in the changelog under Changed.NaNnow shows as selected.Tests
34 new AutoComplete tests cover selection rules for every equality mode including reactive proxies, in-place array changes, groups, disabled suggestions, the virtual scroller, focus and range selection, single mode, and an overridden
isEquals. A spy test fails if rendering, range selection or focus on open go back to comparing against every selected value. The full suite passes (704 tests).