Skip to content

Autocomplete component performance fix - #739

Merged
NJevric merged 2 commits into
masterfrom
fix/728-autocomplete-performance
Nov 19, 2026
Merged

NJevric merged 2 commits into
masterfrom
fix/728-autocomplete-performance

Conversation

@sane6

@sane6 sane6 commented Nov 19, 2026

Copy link
Copy Markdown

Closes #728.

Problem

In multiple mode, isSelected() scanned the whole selection with equals() 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 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.
  • onOptionSelectRange(), findSelectedOptionIndex() and the next/previous selected lookups use the same lookup, so they no longer scan the selection for every suggestion.
  • Objects with no dataKey keep a deep-equality fallback, so equal copies still match, such as the same items returned by a new search.
  • Components that extend AutoComplete and override isEquals still have their rule applied.
  • Docs: the Virtual Scroll section recommends dataKey for 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:

Step Nothing selected, before Nothing selected, after All selected, before All selected, after
Open overlay 661.1 ms 609.7 ms 8,710.8 ms 1,153.8 ms
Hover an option 306.1 ms 305.8 ms 7,857.3 ms 301.3 ms
Re-render, overlay closed (chips only) 2.4 ms 2.2 ms 461.5 ms 433.7 ms
Overlay part (open minus closed re-render) 658.7 ms 607.5 ms 8,249.3 ms 720.1 ms

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

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

@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 19, 2026 11:51pm UTC
openvue-showcase Ready Ready Preview Nov 19, 2026 11:51pm UTC

Request Review

@sane6 sane6 changed the title fix, performance, use set to check option selection status in autocom… Autocomplete component performance fix Nov 19, 2026
@NJevric
NJevric merged commit e875329 into master Nov 19, 2026
11 checks passed

This branch was successfully deployed

1 active deployment
Preview – openvue-showcase — 2a33582d Deployed Nov 19, 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.

AutoComplete (multiple): suggestions overlay is slow with a large number of selected values

2 participants