customElements.define currently always traverses the entire document to find upgrade candidates. Avoid this traversal whenever possible by keeping track of the number of upgrade candidates.
Pull request: https://github.com/WebKit/WebKit/pull/15592