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

related_content is heavy in JSON #66

Closed
peterbe opened this issue Aug 2, 2019 · 5 comments
Closed

related_content is heavy in JSON #66

peterbe opened this issue Aug 2, 2019 · 5 comments

Comments

@peterbe
Copy link
Contributor

peterbe commented Aug 2, 2019

In the renderer, we include all the "state" necessary to render a page. It's encoded as JSON into the HTML file. That's so React can hydrate.
Also, if you click on an internal link, in the sidebar for example, it will only need to download the index.json file which is a lot smaller.

That JSON is getting pretty big and I think there's room for improvement/optimizations.

I analyzed the sizes of sub-keys in the client/build/docs/Web/HTML/Element/**/*.json files and concluded this:

related_content                  5358    47%
prose                            2405    21%
contributors                     1627    14%
browser_compatibility            1307    11%
examples                          412     3%
interactive_example_url            70     0%
mdn_url                            58     0%
title                              34     0%
attributes                          2     0%

E.g. a json like this

This all gets gzipped and stuff but let's get performance as a primary thought now rather than an afterthought. But, let's also not prematurely optimize.

@peterbe
Copy link
Contributor Author

peterbe commented Aug 2, 2019

By the way, because of repetition, related_content compresses better. Gzipped:

related_content                  1108    34%
prose                             892    28%
contributors                      416    13%
browser_compatibility             283     8%
examples                          250     7%
interactive_example_url            83     2%
mdn_url                            78     2%
title                              51     1%
attributes                         22     0%

@peterbe
Copy link
Contributor Author

peterbe commented Sep 4, 2019

One interesting solution is to not hydrate with content from a serialized string. Then you get the best of both worlds. You get no re-render on the client-side and you don't have to include all the heavy state in a serialized JSON string.

@peterbe
Copy link
Contributor Author

peterbe commented Sep 4, 2019

A horribly rough draft is: https://github.com/peterbe/stumptown-renderer/tree/hydrate-based-on-dom
It removes the need to include the state serialized. But it breaks hydration.

@peterbe
Copy link
Contributor Author

peterbe commented Sep 4, 2019

A flaw that can't be escaped is that if you follow that idea it means you simply don't get the event handlers. I.e. all onClicks within the Document will not work. And it can't because we never give the React-in-the-browser a chance to build up its own virtual DOM.

@peterbe
Copy link
Contributor Author

peterbe commented Sep 4, 2019

Perhaps, it's a better idea to break apart index.json into index.json and related_content.json and then lazy-load the sidebar with XHR after initial load. Not great either.

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

No branches or pull requests

2 participants