Most of the internals of jQuery are private, anonymous functions. I don't see how you can profile this. (I've tried as well, with no luck).
Sizzle is the selector-engine powering jQuery. And I suspect that Sizzle uses filter() a lot when querying the DOM, using more complex selectors.
So, at least those function-calls are "ok" and works as intended, and are optimized as much as possible, speed-wise.
Update:
This is the implementation of the dir()
function:
jQuery.dir = function( elem, dir ){
var matched = [], cur = elem[dir];
while ( cur && cur != document ) {
if ( cur.nodeType == 1 )
matched.push( cur );
cur = cur[dir];
}
return matched;
};
nodeType
1 is an ELEMENT_NODE
. The dir()
function filters (or "sanitizes" is you will) the result-set of a given query, to make sure that only DOM elements are returned, and not attributes, text-nodes and so on. (Weather dir()
gets executed, is most likely determined by Sizzle).
To conclude:
You can't skip any of these functions, since they are the core of actually being able to get a hold of anything in the DOM. (Doing a query).
Every time you query the DOM ( $("#something")
) these functions will get executed. On simple queries, perhaps only one or two of the three functions will get executed. Thats probably the reason why there are variations in the number of calls.
As Chetan Sastry points out: You can gain a lot of performance caching your queries and so forth. Have a look at this post for some neat jQuery tricks.