Repository navigation
Multiselect component performance fix - #738
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
NJevric
previously approved these changes
Nov 19, 2026
NJevric
approved these changes
Nov 20, 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 #64 (originally primefaces#8439).
Problem
isSelected()scanned the whole selection withequals()for every option it checked, about 7 times per rendered row, andallSelectedran it for every option. On open,findSelectedOptionIndex()scanned all options for each selected value, and the selected label (selectedValues→getLabelByValue()) did the same on every selection change. The cost was options × selected values: with 10,000 options, selecting all took 41 s and reopening the overlay took 14 s, and with 100,000 options the tab froze.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.findSelectedOptionIndex()builds an option-indexMaponce, instead of scanning all options for every selected value.getLabelByValue()looks options up in aMapby key (computedoptionsBySelectionKey), built once per options change. This speeds up the selected label, the chips and the selected-items count.optionValueordataKeykeep a deep-equality fallback, so equal copies still match.isEqualsstill have their rule applied.optionValueordataKeyfor large lists, and the Basic section explains which in-place changes MultiSelect picks up.Results
Reproducer page, 2,500 options (
optionValue), median of 3 runs (steps over 1 s sampled once). Each step is timed until Vue has patched the DOM and the next frame has started. Open overlay and the scroll jumps compare a MultiSelect with nothing selected against one with all options selected:The select-all checkbox, clicked on the MultiSelect that starts with nothing selected:
With everything selected, opening now takes 62 ms against 49 ms with nothing selected, and scrolling stays within 2 ms of the empty list, so a large selection now costs about the same as an empty one. Select all now costs about the same as deselect all. At 100,000 options, opening takes 487 ms even with nothing selected; most of that is VirtualScroller's deep watcher on
items, which this PR doesn't change.Behavior notes
optionValueordataKeyare still compared by deep equality when they are copies of the options, so they're as slow as before. Option objects selected in the component itself are fast. This is documented.shallowReformarkRawselection array are no longer picked up, and chip labels no longer pick up such changes to theoptionsarray. Assign a new array instead. This is in the changelog under Changed.NaNnow shows as selected.Tests
45 new MultiSelect tests cover selection rules for every equality mode, in-place array changes, groups, filtering, disabled options and the selection limit, select all, focus and range selection, the selected label and chips, and an overridden
isEquals. A spy test fails if rendering, the select-all checkbox orfindSelectedOptionIndex()go back to comparing against every selected value, and another fails if the label goes back to scanning the options for each selected value. The full suite passes (715 tests).