by codedokode · 9y ago · 0 comments
> A brief survey from July 2017 of the uncompressed JS payload sizes for some popular web applications on desktop and mobile:
> Facebook 7.1 MB
I think Facebook should just remove the code they don't need rather than invent new compression methods. There is no way a social network with a chat needs so much JS code.
7Mb of Javascript is too much. 200-300 Kb should be enough to view photos and post comments.
In addition to this, browsers do lazy parsing. They do not fully parse the bodies of functions until the functions are executed.
This is something that would change with the Binary AST, hence allowing much lazier parsing.
https://groups.google.com/forum/#!topic/mozilla.dev.platform...
Note, however, that caching bytecode solves a different problem. Caching bytecode is great for the second+ load of a website. Making initial parsing faster is great for the first load of a website since its latest update. If you consider that Facebook updates its front-end once per hour, for instance, that's a lot for some (not all) websites.
Also, the size improvements may come in useful for applications written in, say, Cordova/PhoneGap.
Some of the design is documented here https://www.facebook.com/notes/facebook-engineering/bigpipe-...
Facebook has done a TON of optimization. The fundamental issue is that Facebook is not a webpage, it's a full application. And the Web as an application platform lags behind native platforms with respect to startup performance.
I explained why Facebook.com is really an app in this comment https://news.ycombinator.com/item?id=14912393
Now compare the functionality of the Facebook Android app vs Facebook desktop webpage (nearly identical) and look at their respective installed sizes (~7MB vs ~180MB).
This proposal will benefit both web apps and web documents. And more importantly, it will allow people to build richer, more sophisticated applications on the web without sweating over extra kilobytes in their JS code size.
I decided to look at Facebook code more closely. It is modular and contains several thousand of small modules. For example, on a news feed page the browser has loaded 66 JS files with total size of 5.7Mb containing 3062 modules [1].
But it is clear that many of those modules are not necessary to display a page. For example, a module with a name "XP2PPaymentRequestDeclineController" that is probably related to payments is not necessary. Or a module with a name "MobileSmsActivationController". Obviously Facebook preloads a lot of code for different dialogs that might be unused most of the times the page is loaded.
Of course I understand that it is very difficult to optimize code when a large team is contantly writing new code and everybody has strict deadlines so there is no time for optimizations, especially if they require serious refactoring.
[1] https://gist.github.com/codedokode/cb506cee367bdb9e1071bc186...
With respect to your example of unnecessary modules, sometimes the dependency trees between modules are non-obvious. But more to the point, the code served to a user is NOT personalized for each individual user and to their specific newsfeed and UI contents. This is actually a performance optimization. Facebook looks at which modules are most commonly required across most users based on their recent activity, and then bundles those common modules into large packages and pushes them aggressively to the browser. This actually results in a very large loading-time win, but ends up overserving some % of extra modules that are not needed by a specific user.
- yet another JavaScript target, with possible incompatibilities, security issues, etc;
- you still need to ship the binaries, which will most likely be much larger (and much slower to parse) than your initial source code;
- "interesting" interactions between Wasm-compiled JS and browser-compiled JS, as well as the DOM, garbage-collection, ...