Side navigation
#4671 closed enhancement (invalid)
Opened May 19, 2009 08:39PM UTC
Closed June 26, 2010 03:39AM UTC
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.
Attachments (0)
Change History (4)
Changed May 19, 2009 08:58PM UTC by comment:1
Changed May 20, 2009 12:16AM UTC by comment:2
Can you provide a test case showing the timing differences?
Changed June 13, 2010 02:50AM UTC by comment:3
component: | unfiled → traversing |
---|
Changed June 26, 2010 03:39AM UTC by comment:4
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"?