mw.loader.store: do one eval per batch, rather than one per module
authorOri Livneh <ori@wikimedia.org>
Tue, 29 Oct 2013 08:35:05 +0000 (01:35 -0700)
committerOri Livneh <ori@wikimedia.org>
Tue, 29 Oct 2013 22:12:08 +0000 (15:12 -0700)
Concatenating module implementations and calling $.globalEval on the result is
reproducibly faster for me than calling $.globalEval for each module.

Change-Id: I70e5bcedb43cd1331720a8e5e6c52cfeabb41ab7

resources/mediawiki/mediawiki.js

index acda5d6..dfb90cc 100644 (file)
@@ -1227,7 +1227,7 @@ var mw = ( function ( $, undefined ) {
                                 */
                                work: function () {
                                        var     reqBase, splits, maxQueryLength, q, b, bSource, bGroup, bSourceGroup,
-                                               source, group, g, i, modules, maxVersion, sourceLoadScript,
+                                               source, concatSource, group, g, i, modules, maxVersion, sourceLoadScript,
                                                currReqBase, currReqBaseLength, moduleMap, l,
                                                lastDotIndex, prefix, suffix, bytesAdded, async;
 
@@ -1256,14 +1256,16 @@ var mw = ( function ( $, undefined ) {
 
                                        mw.loader.store.init();
                                        if ( mw.loader.store.enabled ) {
+                                               concatSource = [];
                                                batch = $.grep( batch, function ( module ) {
                                                        var source = mw.loader.store.get( module );
                                                        if ( source ) {
-                                                               $.globalEval( source );
-                                                               return false; // Don't fetch
+                                                               concatSource.push( source );
+                                                               return false;
                                                        }
-                                                       return true; // Fetch
+                                                       return true;
                                                } );
+                                               $.globalEval( concatSource.join( ';' ) );
                                        }
 
                                        // Early exit if there's nothing to load...