Ticket #13349 (closed bug: fixed)
find function slower since 1.9.0, especially in chrome
| Reported by: | ktmitton@… | Owned by: | dmethvin |
|---|---|---|---|
| Priority: | high | Milestone: | 1.9.1 |
| Component: | traversing | Version: | git |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I noticed when selecting a large array of elements (in my case 11,000+), the jQuery find function would perform much slower in 1.9.0 than in previous versions of jQuery. Looking into the code, it looks like the function was rewritten to use the jQuery.unique function, which was actually mapped to Swizzle.uniqueSort.
It turns out the actual sorting part of the function:
results.sort( sortOrder );
is where the slowdown occurs. I tested in Firefox and IE as well, and the slowdown wasn't as noticeable, but in chrome this added 5-10 seconds to the find.
I created a jsFiddle test http://jsfiddle.net/E6gPN/6/ that creates 12,000 options, runs the find, and outputs the amount of time it took to execute the find.
Change History
comment:2 in reply to: ↑ 1 Changed 4 months ago by anonymous
Replying to dmethvin:
1) In what kind of situation do you have 11,000 DOM elements?
2) Looks like it's unnecessarily going through a unique sort in .find() since for that simple case the results will already be sorted.
1) I know it sounds ridiculous, but I actually do have a few select boxes that are populated with that many options, and I'm not permitted to change that.
2) Yeah, that's what I found. If I had to guess, the unique function call probably just seemed like a nice way to trim down the original code in the function, and the sort probably seemed negligible to the person who rewrote find, and like you said doesn't really change anything.
comment:3 Changed 4 months ago by dmethvin
- Owner set to dmethvin
- Priority changed from undecided to high
- Status changed from open to assigned
- Component changed from unfiled to traversing
- Milestone changed from None to 1.9.1
comment:4 Changed 4 months ago by Dave Methvin
- Status changed from assigned to closed
- Resolution set to fixed
Fix #13349. No need to sort simple .find() cases.
Changeset: 1bbe2b1ded24edf7bf7b18512aff4148591803da
comment:5 Changed 4 months ago by Dave Methvin
Fix #13349. No need to sort simple .find() cases.
Changeset: a5c33fe1f7872a20267ff69905561c8cc55fe3c1
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

1) In what kind of situation do you have 11,000 DOM elements?
2) Looks like it's unnecessarily going through a unique sort in .find() since for that simple case the results will already be sorted.