Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve app load times using code splitting #701

Merged
merged 3 commits into from
Feb 10, 2019
Merged

Conversation

jameshadfield
Copy link
Member

@jameshadfield jameshadfield commented Feb 4, 2019

Currently loading auspice (e.g. nextstrain.org/zika) involves fetching & parsing a JS bundle containing all the relevant app code (324kb minimised), then fetching the dataset JSON(s).

Code-splitting is a feature where the app code (bundle) can be split into separate chunks. This allows a smaller initial fetch+parse and can improve load times for apps. This PR implements code splitting for a number of the components (see below) and improves load time. The time until nextstrain.org/flu/seasonal/h3n2/ha/3y is fully displayed has reduced from 7.9s to 6.3s (average from 4 runs on my machine using the dev server vs live server) and it "feels" faster than this because the map/tree displays and can be interacted with before the entropy/frequency panels).

This image shows the current live version (top) vs this PR (bottom):

lazy_load


The components split into separate bundles:

  • main app (tree, sidebar etc)
  • entropy panel (if you load nextstrain.org/flu/seasonal/h3n2/ha/3y you'll see that the tree appears slightly before the entropy)
  • frequency (same as entropy -- and if you don't require frequencies this code is never fetched)
  • splash page (the auspice one)
  • notifications
  • status page (i.e. the JS for this is never fetched until you actually go to the status page)

I tried splitting out the Map component, which sped up loading even more but looked worse (in my opinion) as there was a white panel next to the tree for ~0.5s.

This PR is available for testing here: https://nextstrain-dev.herokuapp.com

Furthermore, we can now analyse the composition of each bundle using auspice build --analyzeBundle which results in an interactive display (screenshot below). I'll make a separate issue for the improvements that this has flagged up.

image

We now have basic code-splitting in place for a handful of components.
This means that (e.g.) the code for the main interactive page is not fetched
for display of the splash page. This reduces (initial) bundle sizes and should
make for quicker load time.
Useful for understanding bundle contents and making decisions on where to code split / lazy load.
Lazily loading these components means they won't be fetched & displayed until after the main page has rendered. This allows the tree & map to appear faster than previously (smaller bundle to fetch & less JS to parse and render).
@jameshadfield jameshadfield requested a review from trvrb February 4, 2019 02:18
@trvrb
Copy link
Member

trvrb commented Feb 9, 2019

Thanks for the all the detailed work here @jameshadfield. I'm always a fan of performance improvements. Generally in favor of page loads. I looked through code changes and did a fair amount of testing. There does seem to be an improvement, though I seemed to be getting more like ~1s rather than ~2s, but I wasn't being entirely rigorous with Chrome's dev tools.

I don't like the idea of a blank map panel during load.

This is a more a rhetorical question for you: how much additional logic overhead is this bringing? Looking at the code it doesn't look bad at all.

Please feel free to merge.

@jameshadfield jameshadfield merged commit 71e9ea2 into master Feb 10, 2019
@jameshadfield jameshadfield deleted the code-splitting branch February 10, 2019 21:16
jameshadfield added a commit that referenced this pull request Feb 27, 2019
After code splitting (PR #701) the `transition` prototype was,
depending on the dataset, not set on `Selection()` objects.
See d3/d3-selection#185 for some background info.
This commit closes #708
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants