Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Selector: avoid calls to setAttribute( "id" ) by examining selector #431
Additionally, use :scope when available.
This implements the optimization proposed in issue 430. I modified the official benchmark to use
In practice, I've seen this change more than halve the load times of some pages in Edge, which seems to have particularly slow
I don't know if this is the best possible order in which to try alternatives, but it is the best I could come up with. Using the selector verbatim when possible appears to be the fastest across browsers by a small margin. I haven't been able to find a clear winner between
gibson042 left a comment •
I like the general idea, but this size increase is too expensive for "a modest but consistent improvement".
But I am still interested in the size and performance results from two simpler approaches (both in isolation and together):
Thank you for your consideration!
I noticed that simply extracting the scopeSelector function had a size cost:
So after inlining it again, here are the results:
Performance-wise, it seems like a toss-up. I think most of the gain is from avoiding setAttribute() and not the selectors, so :scope benefits more selectors on the browsers that support it, but selector analysis benefits more browsers.