Re: [whatwg] Proposal: Adding methods like getElementById and getElementsByTagName to DocumentFragments

Boris Zbarsky, 2013-06-29 05:02 (Europe/Helsinki):
> On 6/28/13 6:51 PM, Tab Atkins Jr. wrote:
>> querySelector is simply a more powerful querying function than the old
>> DOM methods,
>
> And somewhat slower as a result, note.

If that's true, I would consider that as a bug. It should be really 
simple for an UA implementation to optimize as following

 querySelector("#foo") ->  getElementById("foo")

 querySelectorAll("foo") -> getElementsByTagName("foo")

as long the latter (internal) implementations were available and had 
better performance.

Or, were you really talking about the difference between having to scan 
the string given as a parameter to see if it looked like "simple" 
selector that matches the old DOM method implementation? I understand 
that JS+JIT allows faster method dispatching with getElementById() than 
with querySelector() plus checking the characters of the first 
parameter. I'd *guess* that that difference is meaningless compared to 
walking the element tree or even doing hash lookup for the id which is 
required to implement even the old DOM methods.

-- 
Mikko

Received on Wednesday, 3 July 2013 07:59:32 UTC