Bug Tracker

Opened 7 years ago

Closed 7 years ago

#12913 closed bug (notabug)

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

Reported by: davidtwtong@… 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?

Change History (3)

comment:1 Changed 7 years ago by dmethvin

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/

comment:2 Changed 7 years ago by scottgonzalez

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.

comment:3 Changed 7 years ago by timmywil

Resolution: notabug
Status: newclosed

@scott.gonzalez +1

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

Note: See TracTickets for help on using tickets.