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

[docs] Use Suspense for lazy loading algolia #17451

Merged
merged 5 commits into from
Sep 21, 2019

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Sep 16, 2019

Instead of eagerly loading the Input and waiting for algolia to load we bundle the input and algolia into a chunk and lazy load that one. It allows us to remove the custom retry logic. Previously we retried every 100ms to initialize the docsearch until runtime dependencies were loaded and markup was initialized. The browser takes care of this now.

Hopefully this also means that the sever rendered landing page has no dependencies on the input component which would reduce the initial size a bit.

Not sure I like the use of the Skeleton component here.

@eps1lon eps1lon added docs Improvements or additions to the documentation performance labels Sep 16, 2019
@mui-pr-bot
Copy link

mui-pr-bot commented Sep 16, 2019

Details of bundle changes.

Comparing: e48aeba...0aa4702

bundle parsed diff gzip diff prev parsed current parsed prev gzip current gzip
@material-ui/core 0.00% 0.00% 331,962 331,962 90,633 90,633
@material-ui/core/Paper 0.00% 0.00% 68,660 68,660 20,458 20,458
@material-ui/core/Paper.esm 0.00% 0.00% 62,098 62,098 19,203 19,203
@material-ui/core/Popper 0.00% 0.00% 28,397 28,397 10,159 10,159
@material-ui/core/Textarea 0.00% 0.00% 5,082 5,082 2,132 2,132
@material-ui/core/TrapFocus 0.00% 0.00% 3,766 3,766 1,596 1,596
@material-ui/core/styles/createMuiTheme 0.00% 0.00% 16,348 16,348 5,818 5,818
@material-ui/core/useMediaQuery 0.00% 0.00% 2,488 2,488 1,050 1,050
@material-ui/lab 0.00% 0.00% 154,783 154,783 46,921 46,921
@material-ui/styles 0.00% 0.00% 51,420 51,420 15,288 15,288
@material-ui/system 0.00% 0.00% 15,581 15,581 4,351 4,351
Button 0.00% 0.00% 78,633 78,633 24,021 24,021
Modal 0.00% 0.00% 14,542 14,542 5,114 5,114
Portal 0.00% 0.00% 2,907 2,907 1,318 1,318
Rating 0.00% 0.00% 69,963 69,963 21,856 21,856
Slider 0.00% 0.00% 75,084 75,084 23,184 23,184
colorManipulator 0.00% 0.00% 3,835 3,835 1,519 1,519
docs.landing 0.00% 0.00% 54,267 54,267 14,345 14,345
docs.main -2.74% -2.54% 597,961 581,547 191,048 186,199
packages/material-ui/build/umd/material-ui.production.min.js 0.00% 0.00% 302,849 302,849 87,078 87,078

Generated by 🚫 dangerJS against 0aa4702

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 16, 2019

On this topic of improving the search. It seems that none of the pages under https://material-ui.com/getting-started/* is indexed for v4. Strange.

@eps1lon eps1lon force-pushed the docs/deferred-appsearch branch from 2dce6e5 to 8ebae8f Compare September 17, 2019 07:02
return (
<React.Fragment>
<link
rel="preload"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use prefetch to reduce the priority? https://3perf.com/blog/link-rels/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell

It’s helpful when you need that resource a few seconds after loading the page, and you want to speed it up.

fits exactly how we're using it currently.

Copy link
Member

@oliviertassinari oliviertassinari Sep 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have asked because it might delay another resource, a resource that might we might need to get to an interactive state, previously we were waiting for the interactive state to load this CSS asset. Given that we don't need this asset for the first load, we could delay its loading.

I haven't checked the actual implication, It's only a guess.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what I'm supposed to do with guesses in a code review. The documentation you linked supports the implementation. If there are more important resources blocked by this implementation it would help if you include what these resources are and why you think they are more important.

Just arguing against an implementation with guesses is not helpful.

Copy link
Member

@oliviertassinari oliviertassinari Sep 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was an invitation to explore this path. It seems to be confirmed by https://www.webpagetest.org/video/compare.php?tests=190917_YM_74b7ddcba6319bbfca4d7c222ea68345,190917_1H_0ff4283726ec6cfc83b0f994b87f446b. We load the CSS asset before the interactive state. Could it be a misusage of the available resources early in the loading stage?

Copy link
Member

@oliviertassinari oliviertassinari Sep 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, here is the difference I could notice:

branch
branch

master
master

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why would you care about the order? The user won't notice. What's important is are user metrics like time to first byte or first meaningful paint or time to interactive. None of these are affected in any meaningful way.

You're looking for any difference and calling it a regression which is obvious since something was changed. What's important is the difference for the user not some theoretical internal difference, no?

Even more so why would you think it's ok for a stylesheet to be loaded after time to interactive? It can display search results without styling.

Copy link
Member

@oliviertassinari oliviertassinari Sep 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is only noticeable on a slow connection: https://www.webpagetest.org/video/compare.php?tests=190920_BS_a465ecd007173c07ecbd9e31fc2e1cf4,190920_D1_023f612a117b19cdd554390950f98104. Assuming we have to prioritize the order in which we load the assets, I believe that the CSS asset is less important because the search to be displayed requires the following steps:

  1. The page is interactive
  2. The Algolia JavaScript asset is loaded
  3. The search is visible
  4. The user starts a search

We should be able to start loading the CSS assets at 2, and complete it before 4 triggers.

Copy link
Member

@oliviertassinari oliviertassinari Sep 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, it's not very important, most of our users have a decent connection, move forward as you see fit :)! It would probably only impact synthetic benchmarks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't understand why an asset with preload would block either the suspended chunk or the page becoming interactive. The whole point of this is to signal to the browser: "no biggy if you don't load this but when you have the time start loading this please". I wouldn't bother too much looking into order of the loads because this changes by nature. You should not bother about the order because a dedicated scheduler does that.

There are too many moving parts here that you can't be sure this is a bad change. There are even some metrics that are better with this change. Another issue is that the time to first byte is already slower in the preload benchmark which surely is just random error that already gives the master benchmark a head start.

Like this is no easy graph to read. You can't just look at two numbers and go: yep that's worse. As I read it this change makes the first interaction possible after 8s down from 9s (red is non-interactive because the main thread is blocked):
master:
Screenshot from 2019-09-20 17-39-59

preload:
Screenshot from 2019-09-20 17-39-24

@eps1lon eps1lon force-pushed the docs/deferred-appsearch branch from 8ebae8f to 0aa4702 Compare September 20, 2019 06:31
@oliviertassinari oliviertassinari merged commit ccc470e into mui:master Sep 21, 2019
@eps1lon eps1lon deleted the docs/deferred-appsearch branch September 21, 2019 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants