Giter VIP home page Giter VIP logo

samples-module-loading-comparison's Introduction

Browser module loading tests

This sample takes moment.js and three.js, and prepares them for loading in the browser with ECMAScript modules.

Development

Cloning this repository

Standard stuff :) Hit the "Clone or download" button in the project's GitHub landing page and go from there.

Installing dependencies

NPM packages need to be installed on the root and both src/ subdirectories.

npm i

Gulp needs to be available globally. You can install it by doing:

npm i -g gulp

Building and developing

gulp build

Running the HTTP server

First add cert.pem and key.pem files for TLS. If you don't have these, you can use simplehttp2server to generate them for you. Place them at the root of the clone.

Then:

go run server/server.go

Or, if you don't have go command, you can use the built in HTTP server instead:

gulp serve

HTTP server command line options:

  • --http1: serve over HTTP/1.1 instead of HTTP/2
  • --push: use HTTP/2 push when serving
  • --preload: inject <link rel="preload"> tags for JS dependencies when serving

E.g., to serve over HTTP/1.1 with preload enabled:

go run server/server.go --http1 --preload

Bundled / unbundled tests

The bundled / unbundled test cases are served at the following URLs:

These tests load the files only once, so the results may be noisy. At the toplevel test page https://localhost:44333/ you can run the unbundled test cases repeatedly (25 times) and see the median time.

Synthesized module tree tests

In addition to the real-world library test cases, this HTTP server provides a benchmark for artificial module tree shapes. This is served at https://localhost:44333/synthesized/ and it accepts the following query parameters:

  • depth (default: 5): height of the module dependency tree
  • branch (default: 2): number of child modules non-leaf modules have
  • delay=n (optional): sleep n milliseconds in response handler
  • cacheable (optional): make JavaScript resources cacheable

E.g., this loads a module whose dependency tree is a perfect binary tree of depth 10 (2047 modules in total): https://localhost:44333/synthesized/?depth=10&branch=2

Note: Currently, --push and --preload options are not supported in synthesized tests.

[Experimental] WebBundle tests

Web Bundle is a file format for encapsulating one or more HTTP resources. It allows distributing a large number of module scripts as a single HTTP resource.

You need WebBundle Go tools to generate Web Bundles, which can be installed by this command:

go get -u github.com/WICG/webpackage/go/bundle/cmd/...

Then, this command will generate Web Bundles for the moment.js / three.js tests:

./gen-bundles.sh

As of April 2020, Web Bundles support is implemented only in Chromium-based browsers, behind an experimental feature flag. To enable Web Bundles in Chrome, turn on chrome://flags/#web-bundles flag.

After enabling the flag, drag and drop samples-module-loading-comparison.wbn into Chrome to open it. An index page will be displayed from which you can choose a benchmark to run.

gen-bundles.sh also generates dist/moment/momentjs.wbn and dist/three/threejs.wbn. They only bundle the module scripts for each test. These can be used with dist/{moment,three}/webbundle.html to test Subresource loading with Web Bundles. (Note: this is a proposal in very early stage; experimental implementation is not landed in any browsers as of April 2020.)

samples-module-loading-comparison's People

Contributors

ioslh avatar irori avatar sgomes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

samples-module-loading-comparison's Issues

Problems

image
image
Chrome throw a error when I use mdc which is installed by npm and I have to specific directory/index.js when I import js files

Unbundled, flat imports

During Sam's talk at Chrome Developer Summit he mentioned that the performance of loading Moment.js unbundled was notably worse than bundled. At the moment I'm not able to dig into the tests (still at CDS), but I suspect this is directly related to the lib's request waterfall.

What if the parent page contained a script tag for each module in the lib's dependency tree? This may help sidestep the need to walk every file in the lib's dependency tree in order to discover (and start downloading) each dependency individually. I suspect this will speed up the discovery and download process, especially in a H2 environment.

Optimised vendor libraries

This is a really useful benchmark, just what I was looking for!

I was wondering if there would be a difference if bundled, optimised vendor bundles were used along with unbundled app modules.
Something like ReactHN using react.min.js but it's own scripts unbundled
Would load times improve enough to be as good as bundled or at least good enough to the point where the gains in caching might be a decent tradeoff for larger load times?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.