Skip to content

jQuery find() convention has bad performance #22

@brycec

Description

@brycec

In the jQuery section, there is this convention:

Scope jQuery object queries with find. jsPerf

But the jsPerf cited is actually a different test than the example given. The example prefers $('.sidebar').find('ul') over $('.sidebar ul') and even $('.sidebar > ul') however the jsPerf test is not equivalent to the style guide example because it is essentially $(CACHED_NODE).find('ul') which means it doesn't need to find the first element.

If you take a look at this modified jsPerf here you will see that 'select and find' actually has nearly as bad as performance as the 'find in context of' style, 90% slower than 'find on cached node'. Cascade and 'parent > child' selector are only 50% and 40% respectively.

Essentially, the citation behind this convention is not applicable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions