Select2 slow performance for large list

Select2 slow performance for large list



I have a Select2 widget attached to a dropdown and the dropdown is taking a long time to load (5-10 seconds). The response time gets better as more characters are typed into the search, but the first two or three characters are taking too long.

My list is built in a Select Distinct SQL statement that returns a single column during the preparation, and contains over 30000 items. The column returned from the SQL statement is used for both the Source Attribute and Source Identifier.

Is there a way to make the Select2 widget (or another searchable dropdown) respond faster?

Thank you.

Hi Cody,

No, I'm afraid there is no way to make the Select2 faster. Not an easy one, at least.
The problem is that the Select2 works completely Client side. This means that the list must be complete to it to work.

So, you have at least 2 problems here.

1. Your list will take time to load, on preparation.
2. Every time the javascript will render the list visible when the user types, it will go through a lot of items.

An alternative is to use the Input_autocomplete with a normal input. You can than define that the list will be loaded only when the user types a certain number of times.

Disavantages: Uses server side logic to load the the list every time the input changes, the user needs to click in an element of the list to select an item, because typing it, by default, it is not enough, even if this can be workaraunded with some logic.

Maybe rethink your UI can solve this problem.

Eduardo Jauch