Skip to main content

Bug Tracker

Side navigation

#12913 closed bug (notabug)

Opened November 17, 2012 02:16AM UTC

Closed November 19, 2012 10:31PM UTC

use childElementCount or Element.children.length for $j('#test').children().length to improve performance

Reported by: davidtwtong@gmail.com Owned by:
Priority: high Milestone: 2.0
Component: traversing Version: 1.8.3
Keywords: Cc:
Blocked by: Blocking:
Description

http://jsperf.com/jquery-child-ele-size/10

childElementCount seems to be a lot faster. Looks like it should be used to calculate the number of children for browser that supports it? Might need a new method though... like $j('#test').childrenSize()

What do you think?

Attachments (0)
Change History (3)

Changed November 17, 2012 02:48AM UTC by dmethvin comment:1

component: unfiledtraversing
milestone: None2.0
priority: undecidedhigh

For the 1.x line, using the newer APIs that are unsupported by oldIE generally won't have a good payback. The traversal methods are rarely a bottleneck, and if we still have to support oldIE we're basically doubling the code paths and making the code larger.

jQuery 2.0 is a totally different story though. Since our short pole is IE9, we can take advantage of ES4 and later DOM methods and get rid of the old code (I hope).

Since we don't currently have a ticket for this in 2.0 we might as well use yours.

Just this week, Nicholas Zakas covered quite a few of these APIs:

http://www.nczonline.net/blog/2012/11/13/javascript-apis-youve-never-heard-of/

Changed November 17, 2012 03:14AM UTC by scottgonzalez comment:2

I don't see how this is useful. This is barely related to anything that exists in jQuery today and isn't something we should be adding a new API for.

Changed November 19, 2012 10:31PM UTC by timmywil comment:3

resolution: → notabug
status: newclosed

@scott.gonzalez +1

We may be able to take advantage of childElementSize internally, but this is not a bug.