-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Widget: Optimize attachment of the _untrackClassesElement listener #2037
Conversation
I've checked the bugs Scott fixed and here are what the bugs are about:
Some more references for the commit (ef2e9ba) that introduced the bug this PR fixes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code and its logic loos good to me and makes sense.
I can do some manual testing. It is too bad there are no tests for this, but what about adding some now? Or is it tricky to test for a memory leak / performance issue? |
@fnagel I guess we could add a test for some of these, e.g. https://bugs.jqueryui.com/ticket/15082 as we can access our event handlers list and see if it doesn't grow too much. I'll think about possible tests next week. |
4d2bd24
to
cd0fe70
Compare
Wonderful. I will do some more testing when you finished. |
cd0fe70
to
c0664d7
Compare
@fnagel I added tests for all of the issues except for https://bugs.jqueryui.com/ticket/15136 but that one will be almost identical to the existing tests so it should be good for you to test now. I verified those new tests fail when Scott's change is reverted and - as you can see - they pass on my branch. |
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
c0664d7
to
7a951ef
Compare
@fnagel I added a test case for the This should be ready for your final testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally (reviewed in IDE, running tests and manual testing incl. the demo from issue). Good to merge!
jQuery UI 1.13.1 including this fix has been released: https://blog.jqueryui.com/2022/01/jquery-ui-1-13-1-released/. |
jQuery UI 1.13.0 changed the logic attaching the
_untrackClassesElement
listener in the
_classes
widget method; one of the side effects was callingthis._on
for each node that needed the listener. That caused a severeperformance degradation for large comboboxes as each
_on
jQuery UI callcauses a jQuery
add
call that calls Sizzle'suniqueSort
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