mw.loader: Optimise hot code paths in addEmbeddedCSS()
addEmbeddedCSS() is a big part of the hot code path that moves a module from
state "loaded" to "ready". Especially on repeat views (where most loads
are cache hits from local storage), this is the main thing that JS spends time
on before running scripts (which must wait for the styles to apply first).
* newStyleTag: Avoid use of jQuery.
Before
- jQuery()
- jQuery#init
- jQuery#before
- jQuery#domManip, jQuery#buildFragment, jQuery#inArray
- Node#insertBefore
- Node#appendChild
After
- Node#insertBefore
- Node#appendChild
* getMarker: Store raw Node instead of jQuery object. Makes it easy for other
code to avoid jQuery. And for those that don't, creating a jQuery object is cheap.
Also use querySelector directly since it's ensured by our feature test.
The only cases jQuery/Sizzle accounts with querySelector is IE8 (already excluded
by our feature test), and Opera 12 (in an edge case that doesn't apply to this
selector).
Before
- jQuery
- jQuery#init
- jQuery#find
- Sizzle
- querySelectorAll
- jQuery#pushStack
After
- querySelector
* addEmbeddedCSS: This was needlessly calling the fairly slow .data() method for
all style tags in all browsers. It should've been guarded by IE<=9 if-statement.
The consumer of this data property already had that check. The setter did not.
Before:
- getMarker
- ..
- newStyleTag
- ..
- jQuery#data
- jQuery#each, jQuery#data, internalData, ..
- fireCallbacks
- ..
After
- getMarker
- newStyleTag
- fireCallbacks
- ..
Change-Id: Ie5b5195d337b5d88f0c2ca69d15b13a4fb9d87e2