New issue
Advanced search Search tips

Issue 914942 link

Starred by 2 users

Issue metadata

Status: Closed
Owner: ----
Closed: Dec 14
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: ----
Type: Bug



Sign in to add a comment

Speed: document.head is much slower than document.querySelector('head')

Project Member Reported by jasonjmi...@google.com, Dec 13

Issue description

Intuitively, one might think document.head would be the fastest way to obtain a reference to <head>. However, in Chrome (and Firefox/Safari), querySelector('head') is 40-75% faster.

Benchmark:
https://esbench.com/bench/5c12ae1e4cd7e6009ef61df3

Tweet (context + developer sentiment):
https://twitter.com/_developit/status/1073301597168513029

Implementation: (head is a getter on Document)
https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/dom/document.cc?sq=package:chromium&g=0&l=3301-3307

 
esbench.com is broken either entirely or just for this test: the last task is always the slowest, apparently.
If you switch the order of tasks, document.head will be the fastest.
https://esbench.com/bench/5c137d9f4cd7e6009ef61e22

In a bare fist fight document.head is 3x faster than querySelector:

    console.time('head');
    for (var i = 0; i < 1e6; i++)
      document.head;
    console.timeEnd('head');

    console.time('querySelector');
    for (var i = 0; i < 1e6; i++)
      document.querySelector('head');
    console.timeEnd('querySelector');

Status: Closed (was: Unconfirmed)
Yes - sorry, this got debunked pretty thoroughly on Twitter and I should have closed the issue as well. The test breakage seems likely to be due to reuse of the test iframe.

Sign in to add a comment