mw.loader: Minor clean up and optimisations
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 25 Aug 2016 23:08:56 +0000 (16:08 -0700)
committerKrinkle <krinklemail@gmail.com>
Fri, 26 Aug 2016 23:26:38 +0000 (23:26 +0000)
commitc42bc78530771a7e16433fdf6cfe3b73ed5626b6
treed4bbdaa85c09efb936d6790851fcec13a78cdf5d
parent1a812d498c9032a3d16a4f52e900e3563801513a
mw.loader: Minor clean up and optimisations

* mw.loader.state: Simplify code by removing redundant branch that could set
  the value to what it already was. Also remove the condition for it since
  re-setting it should never happen in practice.
  If it does happen, it's a harmless no-op.

* mw.loader.store.set: Document use cases for descriptor being partial.
  On a most page views, this branch runs for 'site.styles', 'json', 'user',
  'dom-level2-shim', 'mediawiki.hidpi', 'user.options', and 'user.tokens'.
  Aside from group=user modules, the others are skipped or style modules.

* register: Make faster and reduce GC overhead
  (MacBookPro, Chrome canary 52, Vagrant, 566 registered modules)
  Measured using Timeline (JS Profile) and Profile (Allocation Profile).

  - Use typeof instead of isFunction().
  - In resolveIndexedDependencies:
    - Use a for-loop instead of $.each(). This uncovered a JSHint warning for
      making $.map() functions in a loop. Move the function out and re-use it.
    - Use a for-loop instead of $.map().
  - Don't create an empty dependencies array in the registry only to
    dereference it in the next statement.

  Time for register() down from 5-10ms to 3-4ms.
  Memory for register() down
   from 153KB (88% in register, 12% in resolveIndexedDependencies/each/map)
   to 120KB (100% in register, no mention of resolveIndexedDependencies)
  GC down from 350KB to 240KB.

* Remove use of isFunction(). We're not interested in its edge cases of
  native functions in old IE and regex false-positive in Android 2.3.
  For plain user-specified functions, typeof will return 'function'
  in all supported browsers.

Change-Id: I43fc7c7f54d0c279b659d6fddd21673de48f4bc2
resources/src/mediawiki/mediawiki.js