Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jquery autocomplete custom combobox- ui hangs #2014

Closed
akashdeepjaiswal opened this issue Nov 12, 2021 · 11 comments · Fixed by #2037
Closed

jquery autocomplete custom combobox- ui hangs #2014

akashdeepjaiswal opened this issue Nov 12, 2021 · 11 comments · Fixed by #2037

Comments

@akashdeepjaiswal
Copy link

dropdown is too slow to render when data is close 5000. How to limit options like show first 100 data then add option like more data avaible then when clicked on this it bring another 100 and so on

@mgol
Copy link
Member

mgol commented Nov 15, 2021

Thanks for the report. Does the issue you describe exist when jQuery UI 1.12.1 is used or only with jQuery UI 1.13.0 or newer?

@voc0der
Copy link

voc0der commented Nov 19, 2021

Even if it's less than 5000, it slows to crawl in the new one. Been using jQuery UI 1.12.1 for years, with a custom autocompleting combobox I wrote; albeit hacky, it does work excellently with tens of thousands of records in 1.12.1 and lags like crazy in 1.13.0 thus we cannot upgrade.

https://github.com/noblesigma/jQuery.UI.Combobox.Lazyload

@dmethvin
Copy link
Member

Can you provide a link to a simple test case? I'm curious what might have changed.

@mgol
Copy link
Member

mgol commented Dec 1, 2021

Yes, a test case would definitely help.

@fnagel
Copy link
Member

fnagel commented Dec 2, 2021

This is about the https://api.jqueryui.com/autocomplete/ widget, right?

I don't think this widget is able to work with thousands of options. Not even hundreds. I would strongly recommend to use its AJAX filter functionality.

https://api.jqueryui.com/autocomplete/#option-source
https://jqueryui.com/autocomplete/#remote

@voc0der
Copy link

voc0der commented Dec 2, 2021

I will try to provide a test case soon. This is definitely a before I had it working now it doesn't work with the new version thing, sorry guys, I know it sucks I just haven't had much time. The github example admittedly is a bit old and it doesn't self host work again, so it will take me some time to make you a new demo.

It doesn't work well with hundreds of thousands of options, if they get rendered into the DOM, no, but generally if you allow people to type one to two letters, they find it before it gets that big, so in most every case anyways.

Like I said, I hope to have an example for you that doesnt need a server soon since its just JSON.

@voc0der
Copy link

voc0der commented Dec 13, 2021

https://github.com/noblesigma/jQuery.UI.Combobox.Lazyload/tree/master/example/breakingExample

If you download those files locally and load it from a browser, like firefox, you can see that index-working works (just scroll down and wait, and the 2nd chunk will load in that same dropdown), and index-non-working doesn't work. The only difference is the jQueryUI version; and if you really wanted, the json could go up to 20K+ lines in 1.12.1 without breaking, but in 1.13.0 it breaks in under 1.5k.

Sorry it took so long. Good luck. Please let me know if you need help with something.

@mgol
Copy link
Member

mgol commented Dec 17, 2021

Thanks for the test case! That helps a lot.

I did a performance profile on both 1.12.1 & 1.13.0 test cases and it looks like the performance regression is caused by ef2e9ba. The added bindRemoveEvent function triggers this._on calls for all of those elements which takes a lot of time.

@mgol mgol added this to the 1.13.1 milestone Dec 18, 2021
@mgol mgol removed the Needs info label Dec 18, 2021
@fnagel
Copy link
Member

fnagel commented Dec 20, 2021

@noblesigma Thanks for the test case, I now understand what's the issue here!

@mgol Looks like an ugly bug here as Scott's commit fixed a few bugs. Seems like a complicated one. Not sure what to do :-/

mgol added a commit to mgol/jquery-ui that referenced this issue Dec 31, 2021
jQuery UI 1.13.0 changed the logic attaching the `_untrackClassesElement`
listener in the `_classes` widget method; one of the side effects was calling
`this._on` for each node that needed the listener. That caused a severe
performance degradation for large comboboxes as each `_on` jQuery UI call
causes a jQuery `add` call that calls Sizzle's `uniqueSort` underneath.

Instead, collect the nodes that need the listener and then, outside of the loop,
create a jQuery object out of them and attach the listener once. That's still
slower than the jQuery 1.12 version but only slightly: 936 ms to 1.03s on a very
large list on a recent MacBook Pro, compared to ~30 seconds before this patch.

Fixes jquerygh-2014
@mgol
Copy link
Member

mgol commented Dec 31, 2021

I think I have a fix, PTAL: #2037.

mgol added a commit to mgol/jquery-ui that referenced this issue Jan 5, 2022
jQuery UI 1.13.0 changed the logic attaching the `_untrackClassesElement`
listener in the `_classes` widget method; one of the side effects was calling
`this._on` for each node that needed the listener. That caused a severe
performance degradation for large comboboxes as each `_on` jQuery UI call
causes a jQuery `add` call that calls Sizzle's `uniqueSort` underneath.

Instead, collect the nodes that need the listener and then, outside of the loop,
create a jQuery object out of them and attach the listener once. That's still
slower than the jQuery 1.12 version but only slightly: 936 ms to 1.03s on a very
large list on a recent MacBook Pro, compared to ~30 seconds before this patch.

Fixes jquerygh-2014
mgol added a commit to mgol/jquery-ui that referenced this issue Jan 13, 2022
jQuery UI 1.13.0 changed the logic attaching the `_untrackClassesElement`
listener in the `_classes` widget method; one of the side effects was calling
`this._on` for each node that needed the listener. That caused a severe
performance degradation for large comboboxes as each `_on` jQuery UI call
causes a jQuery `add` call that calls Sizzle's `uniqueSort` underneath.

Instead, collect the nodes that need the listener and then, outside of the loop,
create a jQuery object out of them and attach the listener once. That's still
slower than the jQuery 1.12 version but only slightly: 936 ms to 1.03s on a very
large list on a recent MacBook Pro, compared to ~30 seconds before this patch.

Fixes jquerygh-2014
mgol added a commit to mgol/jquery-ui that referenced this issue Jan 13, 2022
jQuery UI 1.13.0 changed the logic attaching the `_untrackClassesElement`
listener in the `_classes` widget method; one of the side effects was calling
`this._on` for each node that needed the listener. That caused a severe
performance degradation for large comboboxes as each `_on` jQuery UI call
causes a jQuery `add` call that calls Sizzle's `uniqueSort` underneath.

Instead, collect the nodes that need the listener and then, outside of the loop,
create a jQuery object out of them and attach the listener once. That's still
slower than the jQuery 1.12 version but only slightly: 936 ms to 1.03s on a very
large list on a recent MacBook Pro, compared to ~30 seconds before this patch.

Fixes jquerygh-2014
mgol added a commit that referenced this issue Jan 15, 2022
jQuery UI 1.13.0 changed the logic attaching the `_untrackClassesElement`
listener in the `_classes` widget method; one of the side effects was calling
`this._on` for each node that needed the listener. That caused a severe
performance degradation for large comboboxes as each `_on` jQuery UI call
causes a jQuery `add` call that calls Sizzle's `uniqueSort` underneath.

Instead, collect the nodes that need the listener and then, outside of the loop,
create a jQuery object out of them and attach the listener once. That's still
slower than the jQuery 1.12 version but only slightly: 936 ms to 1.03s on a very
large list on a recent MacBook Pro, compared to ~30 seconds before this patch.

Fixes gh-2014
Closes gh-2037
@mgol
Copy link
Member

mgol commented Jan 20, 2022

jQuery UI 1.13.1 including a fix for this issue has been released: https://blog.jqueryui.com/2022/01/jquery-ui-1-13-1-released/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

5 participants