diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2022-01-15 01:26:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-15 01:26:23 +0100 |
commit | 0c5becce0e395b89de0f526e857e7ca2717d4ab2 (patch) | |
tree | c1a096b9d08aa473522ff1c5e6b2405f3ee79b5c /tests/unit/selectmenu | |
parent | 4a7cec365be53b17cc9f4a27bb75adea1fc3b14d (diff) | |
download | jquery-ui-0c5becce0e395b89de0f526e857e7ca2717d4ab2.tar.gz jquery-ui-0c5becce0e395b89de0f526e857e7ca2717d4ab2.zip |
Widget: Optimize attachment of the _untrackClassesElement listener
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
Diffstat (limited to 'tests/unit/selectmenu')
-rw-r--r-- | tests/unit/selectmenu/core.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/unit/selectmenu/core.js b/tests/unit/selectmenu/core.js index 05a0e6301..f32cec9b9 100644 --- a/tests/unit/selectmenu/core.js +++ b/tests/unit/selectmenu/core.js @@ -404,4 +404,34 @@ QUnit.test( "Options with hidden attribute should not be rendered", function( as } ); } ); +QUnit.test( "extra listeners created after selection (trac-15078, trac-15152)", function( assert ) { + assert.expect( 3 ); + + var origRemoveListenersCount; + var element = $( "#speed" ).selectmenu(); + var menu = element.selectmenu( "widget" ); + + element.val( "Slow" ); + element.selectmenu( "refresh" ); + origRemoveListenersCount = jQuery._data( menu[ 0 ], "events" ).remove.length; + + element.val( "Fast" ); + element.selectmenu( "refresh" ); + assert.equal( jQuery._data( menu[ 0 ], "events" ).remove.length, + origRemoveListenersCount, + "No extra listeners after typing multiple letters" ); + + element.val( "Faster" ); + element.selectmenu( "refresh" ); + assert.equal( jQuery._data( menu[ 0 ], "events" ).remove.length, + origRemoveListenersCount, + "No extra listeners after typing multiple letters" ); + + element.val( "Slow" ); + element.selectmenu( "refresh" ); + assert.equal( jQuery._data( menu[ 0 ], "events" ).remove.length, + origRemoveListenersCount, + "No extra listeners after typing multiple letters" ); +} ); + } ); |