mw.loader: Optimise hot code paths in addEmbeddedCSS()
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 18 May 2016 18:25:14 +0000 (19:25 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 19 May 2016 18:03:22 +0000 (19:03 +0100)
commita40190f5a594bd26afc59c7f06c66191c2af8d53
treebc37f9099cb21148c28c29b8d8060d605af35272
parent7e7b5c181dd8dd6ee9a59965b6ff91a8cdbf164f
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
jsduck.json
resources/src/mediawiki/mediawiki.js