Skip to content

Multiselect component performance fix - #738

Merged
NJevric merged 3 commits into
masterfrom
fix/64-multiselect-performance
Nov 20, 2026
Merged

NJevric merged 3 commits into
masterfrom
fix/64-multiselect-performance

Conversation

@sane6

@sane6 sane6 commented Nov 19, 2026

Copy link
Copy Markdown

Closes #64 (originally primefaces#8439).

Problem

isSelected() scanned the whole selection with equals() for every option it checked, about 7 times per rendered row, and allSelected ran 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 cached Set (computed selectedKeys). The Set is rebuilt only when the selection changes. Keys follow the existing equality rules: the value itself, the object reference, or the dataKey field.
  • findSelectedOptionIndex() builds an option-index Map once, instead of scanning all options for every selected value.
  • getLabelByValue() looks options up in a Map by key (computed optionsBySelectionKey), built once per options change. This speeds up the selected label, the chips and the selected-items count.
  • Objects with no optionValue or dataKey keep a deep-equality fallback, so equal copies still match.
  • Components that extend MultiSelect and override isEquals still have their rule applied.
  • Docs: the Virtual Scroll section recommends optionValue or dataKey for 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:

Step Nothing selected, before Nothing selected, after All selected, before All selected, after
Open overlay 43.8 ms 48.9 ms 1,107.4 ms 61.9 ms
Scroll to 1% (row 24) 9.3 ms 9.6 ms 12.9 ms 10.7 ms
Scroll to 25% (row 623) 11.4 ms 8.7 ms 26.2 ms 11.0 ms
Scroll to 50% (row 1,247) 8.3 ms 9.3 ms 41.4 ms 11.3 ms
Scroll to 75% (row 1,871) 14.2 ms 9.7 ms 57.6 ms 11.5 ms
Scroll to 100% (row 2,495) 5.8 ms 5.3 ms 32.2 ms 7.3 ms

The select-all checkbox, clicked on the MultiSelect that starts with nothing selected:

Step Before After
Select all 3,514.2 ms 30.1 ms
Deselect all 20.5 ms 16.7 ms

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

  • No public API changes. Selection results are unchanged in every mode.
  • Known limitation: objects with no optionValue or dataKey are 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.
  • Behavior change: in-place changes to a shallowRef or markRaw selection array are no longer picked up, and chip labels no longer pick up such changes to the options array. Assign a new array instead. This is in the changelog under Changed.
  • A selected NaN now 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 or findSelectedOptionIndex() 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).

@vercel

vercel Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openvolt Ready Ready Preview Nov 20, 2026 12:02am UTC
openvue-showcase Ready Ready Preview Nov 20, 2026 12:02am UTC

Request Review

@sane6 sane6 changed the title fix, performance, use set to check option selection status Multiselect component performance fix Nov 19, 2026
NJevric
NJevric previously approved these changes Nov 19, 2026
@NJevric
NJevric merged commit e3a1df2 into master Nov 20, 2026
11 checks passed

This branch was successfully deployed

1 active deployment
Preview – openvue-showcase — 6e2e0bc2 Deployed Nov 20, 2026 by vercel[bot]
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.

MultiSelect: Browser becomes unresponsive when selecting all items (100k records) with VirtualScroller enabled

2 participants