resourceloader: Remove mwPerformance stub and rename mwLoadStart mark
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 20 Apr 2018 00:47:08 +0000 (01:47 +0100)
committerKrinkle <krinklemail@gmail.com>
Mon, 23 Apr 2018 17:59:06 +0000 (17:59 +0000)
Remove the private 'mwPerformance' stub, in favour of simply calling
performance.mark() directly in a conditional, like we do elsewhere for
web APIs that don't exist in all supported browsers.

This mark (part of the W3C User Timing interface), was sometimes used
to measure a delta to mwLoadEnd, whcih is a problem because startup
loads asynchronously. The point it executes is intentionally variable.
What matters is when the overall JS load process ends, which is composed
of multiple requests.

Keep the mark, but rename to 'mwStartup' which better describes its
purpose and can remain useful.

Bug: T160315
Bug: T192623
Change-Id: I6e2049e7252e5c2be3c5bc6617703b62e5edafb4

maintenance/jsduck/eg-iframe.html
resources/src/mediawiki/mediawiki.js
resources/src/startup.js

index 91e0bc1..4c02998 100644 (file)
@@ -35,8 +35,7 @@
        </script>
        <script>
                // Mock startup.js
-               var mwPerformance = { mark: function () {} },
-                       mwNow = Date.now;
+               var mwNow = Date.now;
 
                function startUp() {
                        mw.config = new mw.Map();
index 3fe276b..48c1b09 100644 (file)
                        return $.when.apply( $, all );
                } );
                loading.then( function () {
-                       /* global mwPerformance */
-                       mwPerformance.mark( 'mwLoadEnd' );
+                       if ( window.performance && performance.mark ) {
+                               performance.mark( 'mwLoadEnd' );
+                       }
                        mw.hook( 'resourceloader.loadEnd' ).fire();
                } );
        } );
index cc313c7..41bcbaa 100644 (file)
@@ -5,11 +5,8 @@
  * - Beware: Do not call mwNow before the isCompatible() check.
  */
 
-/* global mw, mwPerformance, mwNow, isCompatible, $VARS, $CODE */
+/* global mw, mwNow, isCompatible, $VARS, $CODE */
 
-window.mwPerformance = ( window.performance && performance.mark ) ? performance : {
-       mark: function () {}
-};
 // Define now() here to ensure valid comparison with mediaWikiLoadEnd (T153819).
 window.mwNow = ( function () {
        var perf = window.performance,
@@ -151,8 +148,9 @@ window.isCompatible = function ( str ) {
        }
 
        window.mediaWikiLoadStart = mwNow();
-       mwPerformance.mark( 'mwLoadStart' );
-
+       if ( window.performance && performance.mark ) {
+               performance.mark( 'mwStartup' );
+       }
        script = document.createElement( 'script' );
        script.src = $VARS.baseModulesUri;
        script.onload = function () {