Page MenuHomePhabricator

Reduce Compact Links initial footprint
Closed, ResolvedPublic

Description

Right now I am seeing 30-40 KB increase (depending on the wiki) when I enable compact language links before user even opens more languages menu.

The module itself is small, 7 KB uncompressed but it pulls in some heavy dependencies such as:

1	"jquery.uls.data"	"35.7 KiB"	36548
2	"jquery.uls"	"33.5 KiB"	34264
3	"jquery.i18n"	"30.4 KiB"	31125
22	"ext.uls.languagenames"	"7.4 KiB"	7614
24	"ext.uls.compactlinks"	"7.2 KiB"	7367
25	"mediawiki.libs.pluralruleparser"	"6.8 KiB"	6971
34	"ext.uls.messages"	"4.9 KiB"	4971

Of these actually only jquery.uls.data, mediawiki.libs.pluralruleparser and of course ext.uls.compactlinks is needed. With some simple changes we seem to be able to bring the initial footprint increase down to 2 KB:

diff --git a/resources/js/ext.uls.compactlinks.js b/resources/js/ext.uls.compactlinks.js
index 5a5ee35..0669a4c 100644
--- a/resources/js/ext.uls.compactlinks.js
+++ b/resources/js/ext.uls.compactlinks.js
@@ -69,7 +69,7 @@
                                return;
                        }
 
-                       mw.loader.using( 'ext.uls.mediawiki' ).done( function () {
+                       mw.loader.using( [ 'ext.uls.init', 'jquery.uls.data' ] ).done( function () {
                                // If we're only a bit beyond max, limit to 7 instead of 9.
                                // FIXME: This assumes the max is 9.
                                self.compactSize = ( self.listSize <= 12 ) ? 7 : max;

This patch doesn't work as is, some code in ext.uls.init uses $.uls.data without depending on jquery.uls.data and $.fn.uls.defaults.languages without depending on jquery.uls (but I'd rather it not to depend on jquery.uls). Also I think this code from ext.uls.mediawiki should be moved to something else, perhaps directly to jquery.uls.data module:

	$.uls.data.addLanguage( 'als', { target: 'gsw' } );

Event Timeline

Restricted Application added subscribers: Zppix, Aklapper. · View Herald TranscriptMay 13 2016, 7:04 AM

Change 289144 had a related patch set uploaded (by Santhosh):
Add jquery.uls.data as depedendency to ext.uls.init

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

Change 289145 had a related patch set uploaded (by Santhosh):
Avoid references to jquery.uls RL module from ext.uls.init

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

Change 289144 merged by jenkins-bot:
Add jquery.uls.data as depedendency to ext.uls.init

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

Change 289146 had a related patch set uploaded (by Santhosh):
Compact language links: Delay loading of jquery.uls module

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

santhosh added a subscriber: santhosh.EditedMay 17 2016, 6:18 AM

After: https://gerrit.wikimedia.org/r/289146, top modules are as follows:

0"jquery.uls.data""35.7 KiB"36548
1"mediawiki.jqueryMsg""16.9 KiB"17313
2"jquery.suggestions""12.4 KiB"12741
3"jquery.makeCollapsible""8.3 KiB"8491
4"ext.uls.compactlinks""7.2 KiB"7421
5"mediawiki.libs.pluralruleparser""6.8 KiB"6971

Change 289145 merged by jenkins-bot:
Avoid references to jquery.uls RL module from ext.uls.init

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

After these patches the additional initial compressed footprint is 2 KB as predicted.

Change 289146 merged by jenkins-bot:
Compact language links: Delay loading of jquery.uls module

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

santhosh claimed this task.May 18 2016, 6:37 AM

In addition to this, we removed some fractions of code from upstream library jquery.uls - though the size reduction may not be in comparable to the above improvements.

Arrbee closed this task as Resolved.May 31 2016, 6:52 AM
Arrbee moved this task from QA to Done on the Language-Q4-2016-Sprint 3 board.