Opened 14 years ago
Closed 13 years ago
#4671 closed enhancement (invalid)
children () is slower than find (), and can be optimized with childNodes
Reported by: | damian.biollo | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | traversing | Version: | 1.3.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I've found that "children" performs slower than "find" and this difference is magnified by the complexity of the web page -- when you get into thousands of divs, it is even noticable by the end user.
This is the code in jQuery to get children: children: function(elem){return jQuery.sibling(elem.firstChild);},
In my test, I called "children" 500x to find some elements. It took 1624 ms. Using "find" took 843ms.
But changing the implementation of children to return elem.childNodes brought the time down to 77ms!
Could you verify this change and update the jQuery implementation. There may be similar speedups available to siblings, parent, etc.
These are numbers from running on FF3.
Change History (4)
comment:1 Changed 14 years ago by
comment:3 Changed 13 years ago by
Component: | unfiled → traversing |
---|
comment:4 Changed 13 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
Lacking some timings showing a problem, I'm going to close this ticket.
Sorry, I was wrong about the 77ms for calling childNodes -- seems that I have to wrap the results with jQuery.makeArray if calling childNodes. The 77ms was not doing a full child search (real time is 1500 ms).
But we still should be able to use "children" to optimize query ... is there any way you can make it work faster than "find"?