Bug Tracker

Opened 8 years ago

Closed 6 years ago

Last modified 5 years ago

#5076 closed enhancement (invalid)

Improving jQuery.filter performances for simple selectors would benefit .is(), .hasClass(), .closest() and .live()

Reported by: lrbabe Owned by: lrbabe
Priority: major Milestone: 1.4
Component: selector Version: 1.3.2
Keywords: filter, performance Cc:
Blocked by: Blocking:


Currently .is() and .hasClass() underlying algorithm has an O(n) complexity while .closest() and .live() complexity is O(n²). However, for simple selectors of the form "div", ".class" or "div.class" the complexity could respectively be O and O(n) by directly checking the nodes without querying the DOM.

The attached patch adds a dozen lines of code to jQuery.filter() to enable this behavior and has a very limited impact on performance for other selectors.

See related post on google groups for additional details and performance numbers: http://groups.google.com/group/jquery-dev/browse_thread/thread/99dc2e890e423bd7

Attachments (1)

patch.txt (1.7 KB) - added by lrbabe 8 years ago.
Fix a bug in the previous proposed patch

Download all attachments as: .zip

Change History (3)

Changed 8 years ago by lrbabe

Attachment: patch.txt added

Fix a bug in the previous proposed patch

comment:1 Changed 6 years ago by dmethvin

Owner: changed from john to lrbabe
Status: newpending

Sorry about the long delay here. Could you re-review the proposed patch to see if it still applies?

comment:2 Changed 6 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

Note: See TracTickets for help on using tickets.