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