Page MenuHomePhabricator

Fix mediaWikiLoadComplete accuracy
Closed, ResolvedPublic

Description

Right now we measure mwLoadStart in mediawiki-core/startup.js using Date#getTime (same as Date.now), but mwLoadEnd using mw.now (which uses navigationStart+performance.now in modern browsers).

The problem is that using mixing these two approaches produces inaccurate results.

For example:

now = ( function () { var perf = window.performance, navStart = perf && perf.timing && perf.timing.navigationStart; return navStart && typeof perf.now === 'function' ? function () { return navStart + perf.now(); } : function () { return +new Date(); }; }() );
a = { d: Date.now(), p: now() }; b = { d: Date.now(), p: now() };
[a, b]
> Array(2)
> 0: Object
> - d: 1482298290210
> - p: 1482298290232.265
> 1: Object
> - d: 1482298290210
> - p: 1482298290232.27

It seems they are consistently off by the same amount within a single tab. In the above example, performance.now() was consistently 22ms later than Date.now() - which would cause things to appear 22ms slower than they really are (assuming end-start; where Date.now is used for start, and perf.now for end).

Browsing other random pages on various domains I get offsets varying from -1 to -90ms. And, at least in Google Chrome, the offset always gets worse as more time goes by (one is ticking faster than the other).

We should account for this offset or work around it.

Proposed solutions:

  1. Move mw.now() definition to startup.js and use it there for mwLoadStart (e.g. define as mwNow and assign to mw.now later).
  2. Or; Compute difference between Date.now() and mw.now() and subtract it when computing mwLoadEnd and mediaWikiLoadComplete in ext.navigationTiming.js

Event Timeline

Krinkle triaged this task as Medium priority.

Change 336913 had a related patch set uploaded (by Krinkle):
resourceloader: Use perf.now() for mediaWikiLoadStart in startup.js

https://gerrit.wikimedia.org/r/336913

Change 336913 merged by jenkins-bot:
resourceloader: Use perf.now() for mediaWikiLoadStart in startup.js

https://gerrit.wikimedia.org/r/336913

Keeping this open until the end of the week to see if we observe any notable changes in the metric measures.

No significant impact on graphs for mediaWikiLoadComplete. Compared with timeShift(-7d) and movingAverage(30min). 1.29.0-wmf.12 was deployed to all wikis between 7PM and 10PM on Thursday, 16 February.

Coal:

  • median, overal: Unaffected (~920ms)

Graphite/carbon:

  • median, overall: Unaffected (~850ms)
  • p75, desktop, anonymous: Unaffected (~ 1.1s)
  • p95, desktop, anonymous: Unaffected (~ 4.0s)
  • p75, mobile, anonymous: 0.1s faster (before: 2.1-2.3s; after: 1.9-2.2s)
  • p95, mobile, anonymous: Unaffected (~ 4.9s - 6.5s)