mw.inspect: Include templates and messages in size
authorSam Smith <me@samsmith.io>
Fri, 24 Feb 2017 10:08:07 +0000 (10:08 +0000)
committerSam Smith <git@samsmith.io>
Tue, 28 Feb 2017 10:29:09 +0000 (10:29 +0000)
Currently, mw.inspect#getModuleSize omits the size of templates and
messages while calculating a ResourceLoader module's size despite them
being included in the module's definition.

Change-Id: Ib8d52c901a8e1656b8b6996762bfbff3af16a834

resources/src/mediawiki/mediawiki.inspect.js

index fdaa989..6b3971e 100644 (file)
                                payload += $.byteLength( module.script.toString() );
                        }
 
+                       // Tally templates and messages. Calculate their JSON size so that keys
+                       // are included in the module size - in the case of messages, keys can be
+                       // longer than values - and so that empty objects are also included.
+                       $.each( [ module.templates, module.messages ], function ( i, object ) {
+                               if ( object ) {
+                                       payload += $.byteLength( JSON.stringify( object ) );
+                               }
+                       } );
+
                        return payload;
                },