Skip to content

Conversation

@deefour
Copy link
Contributor

@deefour deefour commented Sep 14, 2015

Previously, on every call to updateOriginalInput(), a brand new array of
options for every value in selectize.items would be created and the
entire HTML string would replace all children of the raw input source.

When doing something like

selectize.addItems(_.keys(selectize.options));

for a few hundred options, this becomes very sluggish.


This PR takes a smarter approach, only removing and adding individual
options from the input source as necessary.

The bottleneck is the repeated use of jQuery's html() method with large
DOM updates. For ~300 options this was originally spending 30154ms in
appendChild. Now it spends only 330.9ms.

Previously, on every call to updateOriginalInput(), a brand new array of
options for every value in selectize.items would be created and the
entire HTML string would replace all children of the raw input source.

When doing something like

selectize.addItems(_.keys(selectize.options));

for a few hundred options, this becomes very sluggish.

This takes a smarter approach, only removing and adding individual
options from the input source as necessary.

The bottleneck is the repeated use of jQuery's html() method with large
DOM updates. For ~300 options this was originally taking 30154ms in
appendChild. Now it spends only 330.9ms.
@andrewbaldock
Copy link

+1 thank you for this. Using the drag-and-drop plugin on more than 10 items was unbearably slow, this fixes it. Nice work.

@deefour
Copy link
Contributor Author

deefour commented Oct 22, 2015

@andrewbaldock I fixed a bug (see above commit) with a blank/default option being added in situations where the select wasn't actually without options.

@deefour
Copy link
Contributor Author

deefour commented Nov 16, 2018

Closing this in favor of #1460

@deefour deefour closed this Nov 16, 2018
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.

2 participants